diff options
7 files changed, 11 insertions, 73 deletions
diff --git a/csharp/src/ProtocolBuffers.Test/Collections/RepeatedFieldTest.cs b/csharp/src/ProtocolBuffers.Test/Collections/RepeatedFieldTest.cs index 6eff8683..25be7731 100644 --- a/csharp/src/ProtocolBuffers.Test/Collections/RepeatedFieldTest.cs +++ b/csharp/src/ProtocolBuffers.Test/Collections/RepeatedFieldTest.cs @@ -241,18 +241,12 @@ namespace Google.Protobuf.Collections var list = new RepeatedField<string> { "first", "second" }; using (var enumerator = list.GetEnumerator()) { - Assert.Throws<InvalidOperationException>(() => enumerator.Current.GetHashCode()); Assert.IsTrue(enumerator.MoveNext()); Assert.AreEqual("first", enumerator.Current); Assert.IsTrue(enumerator.MoveNext()); Assert.AreEqual("second", enumerator.Current); Assert.IsFalse(enumerator.MoveNext()); - Assert.Throws<InvalidOperationException>(() => enumerator.Current.GetHashCode()); Assert.IsFalse(enumerator.MoveNext()); - enumerator.Reset(); - Assert.Throws<InvalidOperationException>(() => enumerator.Current.GetHashCode()); - Assert.IsTrue(enumerator.MoveNext()); - Assert.AreEqual("first", enumerator.Current); } } diff --git a/csharp/src/ProtocolBuffers/ByteString.cs b/csharp/src/ProtocolBuffers/ByteString.cs index d5b7aee9..738f020e 100644 --- a/csharp/src/ProtocolBuffers/ByteString.cs +++ b/csharp/src/ProtocolBuffers/ByteString.cs @@ -134,6 +134,8 @@ namespace Google.Protobuf /// Constructs a ByteString from the given array. The contents
/// are copied, so further modifications to the array will not
/// be reflected in the returned ByteString.
+ /// This method can also be invoked in <c>ByteString.CopyFrom(0xaa, 0xbb, ...)</c> form
+ /// which is primarily useful for testing.
/// </summary>
public static ByteString CopyFrom(params byte[] bytes)
{
diff --git a/csharp/src/ProtocolBuffers/Collections/RepeatedField.cs b/csharp/src/ProtocolBuffers/Collections/RepeatedField.cs index b6b52cb9..8375ae0b 100644 --- a/csharp/src/ProtocolBuffers/Collections/RepeatedField.cs +++ b/csharp/src/ProtocolBuffers/Collections/RepeatedField.cs @@ -44,9 +44,9 @@ namespace Google.Protobuf.Collections public sealed class RepeatedField<T> : IList<T>, IList, IDeepCloneable<RepeatedField<T>>, IEquatable<RepeatedField<T>>, IFreezable { private static readonly T[] EmptyArray = new T[0]; + private const int MinArraySize = 8; private bool frozen; - private const int MinArraySize = 8; private T[] array = EmptyArray; private int count = 0; @@ -259,7 +259,6 @@ namespace Google.Protobuf.Collections public int Count { get { return count; } } - // TODO(jonskeet): If we implement freezing, make this reflect it. public bool IsReadOnly { get { return IsFrozen; } } public void Add(RepeatedField<T> values) @@ -289,14 +288,12 @@ namespace Google.Protobuf.Collections } } - public RepeatedField<T>.Enumerator GetEnumerator() - { - return new Enumerator(this); - } - - IEnumerator<T> IEnumerable<T>.GetEnumerator() + public IEnumerator<T> GetEnumerator() { - return GetEnumerator(); + for (int i = 0; i < count; i++) + { + yield return array[i]; + } } public override bool Equals(object obj) @@ -468,55 +465,6 @@ namespace Google.Protobuf.Collections } Remove((T)value); } - #endregion - - public struct Enumerator : IEnumerator<T> - { - private int index; - private readonly RepeatedField<T> field; - - public Enumerator(RepeatedField<T> field) - { - this.field = field; - this.index = -1; - } - - public bool MoveNext() - { - if (index + 1 >= field.Count) - { - index = field.Count; - return false; - } - index++; - return true; - } - - public void Reset() - { - index = -1; - } - - public T Current - { - get - { - if (index == -1 || index >= field.count) - { - throw new InvalidOperationException(); - } - return field.array[index]; - } - } - - object IEnumerator.Current - { - get { return Current; } - } - - public void Dispose() - { - } - } + #endregion } } diff --git a/csharp/src/ProtocolBuffers/FrameworkPortability.cs b/csharp/src/ProtocolBuffers/FrameworkPortability.cs index f3da5333..082eb2e1 100644 --- a/csharp/src/ProtocolBuffers/FrameworkPortability.cs +++ b/csharp/src/ProtocolBuffers/FrameworkPortability.cs @@ -40,6 +40,7 @@ namespace Google.Protobuf /// </summary>
internal static class FrameworkPortability
{
+ // TODO(jtattermusch): is this still a thing?
// The value of RegexOptions.Compiled is 8. We can test for the presence at
// execution time using Enum.IsDefined, so a single build will do the right thing
// on each platform.
diff --git a/csharp/src/ProtocolBuffers/InvalidProtocolBufferException.cs b/csharp/src/ProtocolBuffers/InvalidProtocolBufferException.cs index 87b283f2..4f89347d 100644 --- a/csharp/src/ProtocolBuffers/InvalidProtocolBufferException.cs +++ b/csharp/src/ProtocolBuffers/InvalidProtocolBufferException.cs @@ -79,12 +79,6 @@ namespace Google.Protobuf "Protocol message end-group tag did not match expected tag.");
}
- internal static InvalidProtocolBufferException InvalidWireType()
- {
- return new InvalidProtocolBufferException(
- "Protocol message tag had invalid wire type.");
- }
-
internal static InvalidProtocolBufferException RecursionLimitExceeded()
{
return new InvalidProtocolBufferException(
diff --git a/csharp/src/ProtocolBuffers/ProtocolBuffers.csproj b/csharp/src/ProtocolBuffers/ProtocolBuffers.csproj index f529c19a..402d6612 100644 --- a/csharp/src/ProtocolBuffers/ProtocolBuffers.csproj +++ b/csharp/src/ProtocolBuffers/ProtocolBuffers.csproj @@ -111,7 +111,6 @@ <ItemGroup>
<None Include="Google.Protobuf.nuspec" />
</ItemGroup>
- <ItemGroup />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
diff --git a/csharp/src/ProtocolBuffers/Reflection/IFieldAccessor.cs b/csharp/src/ProtocolBuffers/Reflection/IFieldAccessor.cs index b631d34f..3f4f05f4 100644 --- a/csharp/src/ProtocolBuffers/Reflection/IFieldAccessor.cs +++ b/csharp/src/ProtocolBuffers/Reflection/IFieldAccessor.cs @@ -42,7 +42,7 @@ namespace Google.Protobuf.Reflection /// </summary> FieldDescriptor Descriptor { get; } - // TODO: Should the argument type for these messages by IReflectedMessage? + // TODO: Should the argument type for these messages be IReflectedMessage? /// <summary> /// Clears the field in the specified message. (For repeated fields, |