aboutsummaryrefslogtreecommitdiff
path: root/csharp/src/ProtocolBuffers/Collections/RepeatedField.cs
diff options
context:
space:
mode:
Diffstat (limited to 'csharp/src/ProtocolBuffers/Collections/RepeatedField.cs')
-rw-r--r--csharp/src/ProtocolBuffers/Collections/RepeatedField.cs59
1 files changed, 57 insertions, 2 deletions
diff --git a/csharp/src/ProtocolBuffers/Collections/RepeatedField.cs b/csharp/src/ProtocolBuffers/Collections/RepeatedField.cs
index ed311494..b6b52cb9 100644
--- a/csharp/src/ProtocolBuffers/Collections/RepeatedField.cs
+++ b/csharp/src/ProtocolBuffers/Collections/RepeatedField.cs
@@ -41,7 +41,7 @@ namespace Google.Protobuf.Collections
/// restrictions (no null values) and capabilities (deep cloning and freezing).
/// </summary>
/// <typeparam name="T">The element type of the repeated field.</typeparam>
- public sealed class RepeatedField<T> : IList<T>, IDeepCloneable<RepeatedField<T>>, IEquatable<RepeatedField<T>>, IFreezable
+ public sealed class RepeatedField<T> : IList<T>, IList, IDeepCloneable<RepeatedField<T>>, IEquatable<RepeatedField<T>>, IFreezable
{
private static readonly T[] EmptyArray = new T[0];
@@ -376,6 +376,7 @@ namespace Google.Protobuf.Collections
this.CheckMutable();
EnsureSize(count + 1);
Array.Copy(array, index, array, index + 1, count - index);
+ array[index] = item;
count++;
}
@@ -415,7 +416,60 @@ namespace Google.Protobuf.Collections
array[index] = value;
}
}
-
+
+ #region Explicit interface implementation for IList and ICollection.
+ bool IList.IsFixedSize { get { return IsFrozen; } }
+
+ void ICollection.CopyTo(Array array, int index)
+ {
+ Array.Copy(this.array, 0, array, index, count);
+ }
+
+ bool ICollection.IsSynchronized { get { return false; } }
+
+ object ICollection.SyncRoot { get { return this; } }
+
+ object IList.this[int index]
+ {
+ get { return this[index]; }
+ set { this[index] = (T)value; }
+ }
+
+ int IList.Add(object value)
+ {
+ Add((T) value);
+ return count - 1;
+ }
+
+ bool IList.Contains(object value)
+ {
+ return (value is T && Contains((T)value));
+ }
+
+ int IList.IndexOf(object value)
+ {
+ if (!(value is T))
+ {
+ return -1;
+ }
+ return IndexOf((T)value);
+ }
+
+ void IList.Insert(int index, object value)
+ {
+ Insert(index, (T) value);
+ }
+
+ void IList.Remove(object value)
+ {
+ if (!(value is T))
+ {
+ return;
+ }
+ Remove((T)value);
+ }
+ #endregion
+
public struct Enumerator : IEnumerator<T>
{
private int index;
@@ -431,6 +485,7 @@ namespace Google.Protobuf.Collections
{
if (index + 1 >= field.Count)
{
+ index = field.Count;
return false;
}
index++;