public sealed class RepeatedField<T> : IList<T>, IList, IDeepCloneable<RepeatedField<T>>, IEquatable<RepeatedField<T>>, IReadOnlyList<T>
The contents of a repeated field: essentially, a collection with some extra restrictions (no null values) and capabilities (deep cloning).
Namespace
Google.Protobuf.CollectionsAssembly
Google.Protobuf.dll
Type Parameter | |
---|---|
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
Capacity
public int Capacity { get; set; }
Gets and sets the capacity of the RepeatedField's internal array. WHen set, the internal array is reallocated to the given capacity.
Property Value | |
---|---|
Type | Description |
Int32 |
Count
public int Count { get; }
Gets the number of elements contained in the collection.
Property Value | |
---|---|
Type | Description |
Int32 |
IsReadOnly
public bool IsReadOnly { get; }
Gets a value indicating whether the collection is read-only.
Property Value | |
---|---|
Type | Description |
Boolean |
Item[Int32]
public T this[int index] { get; set; }
Gets or sets the item at the specified index.
Parameter | |
---|---|
Name | Description |
index | Int32 The zero-based index of the element to get or set. |
Property Value | |
---|---|
Type | Description |
T | The element at the specified index. |
Methods
Add(T)
public void Add(T item)
Adds the specified item to the collection.
Parameter | |
---|---|
Name | Description |
item | T The item to add. |
Add(IEnumerable<T>)
public void Add(IEnumerable<T> values)
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.
Parameter | |
---|---|
Name | Description |
values | IEnumerable<T> The values to add to this collection. |
AddEntriesFrom(CodedInputStream, FieldCodec<T>)
public void AddEntriesFrom(CodedInputStream input, FieldCodec<T> codec)
Adds the entries from the given input stream, decoding them with the specified codec.
Parameters | |
---|---|
Name | Description |
input | CodedInputStream The input stream to read from. |
codec | FieldCodec<T> The codec to use in order to read each entry. |
AddEntriesFrom(ref ParseContext, FieldCodec<T>)
public void AddEntriesFrom(ref ParseContext ctx, FieldCodec<T> codec)
Adds the entries from the given parse context, decoding them with the specified codec.
Parameters | |
---|---|
Name | Description |
ctx | ParseContext The input to read from. |
codec | FieldCodec<T> The codec to use in order to read each entry. |
AddRange(IEnumerable<T>)
public void AddRange(IEnumerable<T> values)
Adds all of the specified values into this collection.
Parameter | |
---|---|
Name | Description |
values | IEnumerable<T> The values to add to this collection. |
CalculateSize(FieldCodec<T>)
public int CalculateSize(FieldCodec<T> codec)
Calculates the size of this collection based on the given codec.
Parameter | |
---|---|
Name | Description |
codec | FieldCodec<T> The codec to use when encoding each field. |
Returns | |
---|---|
Type | Description |
Int32 | The number of bytes that would be written to an output by one of the |
Clear()
public void Clear()
Removes all items from the collection.
Clone()
public RepeatedField<T> Clone()
Creates a deep clone of this repeated field.
Returns | |
---|---|
Type | Description |
RepeatedField<T> | A deep clone of this repeated field. |
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)
public bool Contains(T item)
Determines whether this collection contains the given item.
Parameter | |
---|---|
Name | Description |
item | T The item to find. |
Returns | |
---|---|
Type | Description |
Boolean |
|
CopyTo(T[], Int32)
public void CopyTo(T[] array, int arrayIndex)
Copies this collection to the given array.
Parameters | |
---|---|
Name | Description |
array | T[] The array to copy to. |
arrayIndex | Int32 The first index of the array to copy to. |
Equals(RepeatedField<T>)
public bool Equals(RepeatedField<T> other)
Compares this repeated field with another for equality.
Parameter | |
---|---|
Name | Description |
other | RepeatedField<T> The repeated field to compare this with. |
Returns | |
---|---|
Type | Description |
Boolean |
|
Equals(Object)
public override bool Equals(object obj)
Determines whether the specified , is equal to this instance.
Parameter | |
---|---|
Name | Description |
obj | Object The to compare with this instance. |
Returns | |
---|---|
Type | Description |
Boolean |
|
GetEnumerator()
public IEnumerator<T> GetEnumerator()
Returns an enumerator that iterates through the collection.
Returns | |
---|---|
Type | Description |
IEnumerator<T> | An enumerator that can be used to iterate through the collection. |
GetHashCode()
public override int GetHashCode()
Returns a hash code for this instance.
Returns | |
---|---|
Type | Description |
Int32 | A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. |
IndexOf(T)
public int IndexOf(T item)
Returns the index of the given item within the collection, or -1 if the item is not present.
Parameter | |
---|---|
Name | Description |
item | T The item to find in the collection. |
Returns | |
---|---|
Type | Description |
Int32 | The zero-based index of the item, or -1 if it is not found. |
Insert(Int32, T)
public void Insert(int index, T item)
Inserts the given item at the specified index.
Parameters | |
---|---|
Name | Description |
index | Int32 The index at which to insert the item. |
item | T The item to insert. |
Remove(T)
public bool Remove(T item)
Removes the specified item from the collection
Parameter | |
---|---|
Name | Description |
item | T The item to remove. |
Returns | |
---|---|
Type | Description |
Boolean |
|
RemoveAt(Int32)
public void RemoveAt(int index)
Removes the item at the given index.
Parameter | |
---|---|
Name | Description |
index | Int32 The zero-based index of the item to remove. |
ToString()
public override string ToString()
Returns a string representation of this repeated field, in the same way as it would be represented by the default JSON formatter.
Returns | |
---|---|
Type | Description |
String |
WriteTo(CodedOutputStream, FieldCodec<T>)
public void WriteTo(CodedOutputStream output, FieldCodec<T> codec)
Writes the contents of this collection to the given CodedOutputStream, encoding each value using the specified codec.
Parameters | |
---|---|
Name | Description |
output | CodedOutputStream The output stream to write to. |
codec | FieldCodec<T> The codec to use when encoding each value. |
WriteTo(ref WriteContext, FieldCodec<T>)
public void WriteTo(ref WriteContext ctx, FieldCodec<T> codec)
Writes the contents of this collection to the given write context, encoding each value using the specified codec.
Parameters | |
---|---|
Name | Description |
ctx | WriteContext The write context to write to. |
codec | FieldCodec<T> The codec to use when encoding each value. |