Class RepeatedField<T>
The contents of a repeated field: essentially, a collection with some extra restrictions (no null values) and capabilities (deep cloning).
Inheritance
Implements
Inherited Members
Namespace: Google.Protobuf.Collections
Assembly: Google.Protobuf.dll
Syntax
public sealed class RepeatedField<T> : IList<T>, ICollection<T>, IList, ICollection, IDeepCloneable<RepeatedField<T>>, IEquatable<RepeatedField<T>>, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable
Type Parameters
| Name | Description |
|---|---|
| T | The element type of the repeated field. |
Remarks
This implementation does not generally prohibit the use of types which are not supported by Protocol Buffers but nor does it guarantee that all operations will work in such cases.
Properties
Count
Gets the number of elements contained in the collection.
Declaration
public int Count { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
Implements
IsReadOnly
Gets a value indicating whether the collection is read-only.
Declaration
public bool IsReadOnly { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
Implements
Item[Int32]
Gets or sets the item at the specified index.
Declaration
public T this[int index] { get; set; }
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | index | The zero-based index of the element to get or set. |
Property Value
| Type | Description |
|---|---|
| T | The element at the specified index. |
Implements
Methods
Add(T)
Adds the specified item to the collection.
Declaration
public void Add(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | The item to add. |
Implements
Add(IEnumerable<T>)
Adds all of the specified values into this collection. This method is present to allow repeated fields to be constructed from queries within collection initializers. Within non-collection-initializer code, consider using the equivalent AddRange(IEnumerable<T>) method instead for clarity.
Declaration
public void Add(IEnumerable<T> values)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.IEnumerable<T> | values | The values to add to this collection. |
AddEntriesFrom(CodedInputStream, FieldCodec<T>)
Adds the entries from the given input stream, decoding them with the specified codec.
Declaration
public void AddEntriesFrom(CodedInputStream input, FieldCodec<T> codec)
Parameters
| Type | Name | Description |
|---|---|---|
| CodedInputStream | input | The input stream to read from. |
| FieldCodec<T> | codec | The codec to use in order to read each entry. |
AddRange(IEnumerable<T>)
Adds all of the specified values into this collection.
Declaration
public void AddRange(IEnumerable<T> values)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.IEnumerable<T> | values | The values to add to this collection. |
CalculateSize(FieldCodec<T>)
Calculates the size of this collection based on the given codec.
Declaration
public int CalculateSize(FieldCodec<T> codec)
Parameters
| Type | Name | Description |
|---|---|---|
| FieldCodec<T> | codec | The codec to use when encoding each field. |
Returns
| Type | Description |
|---|---|
| System.Int32 | The number of bytes that would be written to a CodedOutputStream by WriteTo(CodedOutputStream, FieldCodec<T>), using the same codec. |
Clear()
Removes all items from the collection.
Declaration
public void Clear()
Implements
Clone()
Creates a deep clone of this repeated field.
Declaration
public RepeatedField<T> Clone()
Returns
| Type | Description |
|---|---|
| RepeatedField<T> | A deep clone of this repeated field. |
Implements
Remarks
If the field type is a message type, each element is also cloned; otherwise, it is assumed that the field type is primitive (including string and bytes, both of which are immutable) and so a simple copy is equivalent to a deep clone.
Contains(T)
Determines whether this collection contains the given item.
Declaration
public bool Contains(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | The item to find. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
Implements
CopyTo(T[], Int32)
Copies this collection to the given array.
Declaration
public void CopyTo(T[] array, int arrayIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| T[] | array | The array to copy to. |
| System.Int32 | arrayIndex | The first index of the array to copy to. |
Implements
Equals(RepeatedField<T>)
Compares this repeated field with another for equality.
Declaration
public bool Equals(RepeatedField<T> other)
Parameters
| Type | Name | Description |
|---|---|---|
| RepeatedField<T> | other | The repeated field to compare this with. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
Implements
Equals(Object)
Determines whether the specified System.Object, is equal to this instance.
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | obj | The System.Object to compare with this instance. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
Overrides
GetEnumerator()
Returns an enumerator that iterates through the collection.
Declaration
public IEnumerator<T> GetEnumerator()
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerator<T> | An enumerator that can be used to iterate through the collection. |
Implements
GetHashCode()
Returns a hash code for this instance.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| System.Int32 | A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. |
Overrides
IndexOf(T)
Returns the index of the given item within the collection, or -1 if the item is not present.
Declaration
public int IndexOf(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | The item to find in the collection. |
Returns
| Type | Description |
|---|---|
| System.Int32 | The zero-based index of the item, or -1 if it is not found. |
Implements
Insert(Int32, T)
Inserts the given item at the specified index.
Declaration
public void Insert(int index, T item)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | index | The index at which to insert the item. |
| T | item | The item to insert. |
Implements
Remove(T)
Removes the specified item from the collection
Declaration
public bool Remove(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | The item to remove. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
Implements
RemoveAt(Int32)
Removes the item at the given index.
Declaration
public void RemoveAt(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | index | The zero-based index of the item to remove. |
Implements
ToString()
Returns a string representation of this repeated field, in the same way as it would be represented by the default JSON formatter.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| System.String |
Overrides
WriteTo(CodedOutputStream, FieldCodec<T>)
Writes the contents of this collection to the given CodedOutputStream, encoding each value using the specified codec.
Declaration
public void WriteTo(CodedOutputStream output, FieldCodec<T> codec)
Parameters
| Type | Name | Description |
|---|---|---|
| CodedOutputStream | output | The output stream to write to. |
| FieldCodec<T> | codec | The codec to use when encoding each value. |
Explicit Interface Implementations
ICollection.CopyTo(Array, Int32)
Declaration
void ICollection.CopyTo(Array array, int index)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Array | array | |
| System.Int32 | index |
Implements
ICollection.IsSynchronized
Declaration
bool ICollection.IsSynchronized { get; }
Returns
| Type | Description |
|---|---|
| System.Boolean |
Implements
ICollection.SyncRoot
Declaration
object ICollection.SyncRoot { get; }
Returns
| Type | Description |
|---|---|
| System.Object |
Implements
IEnumerable.GetEnumerator()
Returns an enumerator that iterates through a collection.
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
| Type | Description |
|---|---|
| System.Collections.IEnumerator | An System.Collections.IEnumerator object that can be used to iterate through the collection. |
Implements
IList.Add(Object)
Declaration
int IList.Add(object value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | value |
Returns
| Type | Description |
|---|---|
| System.Int32 |
Implements
IList.Contains(Object)
Declaration
bool IList.Contains(object value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | value |
Returns
| Type | Description |
|---|---|
| System.Boolean |
Implements
IList.IndexOf(Object)
Declaration
int IList.IndexOf(object value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | value |
Returns
| Type | Description |
|---|---|
| System.Int32 |
Implements
IList.Insert(Int32, Object)
Declaration
void IList.Insert(int index, object value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | index | |
| System.Object | value |
Implements
IList.IsFixedSize
Declaration
bool IList.IsFixedSize { get; }
Returns
| Type | Description |
|---|---|
| System.Boolean |
Implements
IList.Item[Int32]
Declaration
object IList.this[int index] { get; set; }
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | index |
Returns
| Type | Description |
|---|---|
| System.Object |
Implements
IList.Remove(Object)
Declaration
void IList.Remove(object value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | value |