public sealed class RepeatedField<T> : IList<T>, ICollection<T>, IList, ICollection, IDeepCloneable<RepeatedField<T>>, IEquatable<RepeatedField<T>>, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable
The contents of a repeated field: essentially, a collection with some extra restrictions (no null values) and capabilities (deep cloning).
Implements
IList, ICollection, IList, ICollection, IDeepCloneableRepeatedField, IEquatableRepeatedField, IReadOnlyList, IReadOnlyCollection, IEnumerable, IEnumerableNamespace
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. The new value is less than .
Property Value | |
---|---|
Type | Description |
int |
Count
public int Count { get; }
Gets the number of elements contained in the collection.
Property Value | |
---|---|
Type | Description |
int |
IsReadOnly
public bool IsReadOnly { get; }
Gets a value indicating whether the collection is read-only.
Property Value | |
---|---|
Type | Description |
bool |
this[int]
public T this[int index] { get; set; }
Gets or sets the item at the specified index.
Parameter | |
---|---|
Name | Description |
index |
int The zero-based index of the element to get or set. |
Property Value | |
---|---|
Type | Description |
T |
The element at the specified index. |
Methods
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 The values to add to this collection. |
Add(T)
public void Add(T item)
Adds the specified item to the collection.
Parameter | |
---|---|
Name | Description |
item |
T The item to add. |
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 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 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 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 The codec to use when encoding each field. |
Returns | |
---|---|
Type | Description |
int |
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 |
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 |
bool |
|
CopyTo(T[], int)
public void CopyTo(T[] array, int arrayIndex)
Copies this collection to the given array.
Parameters | |
---|---|
Name | Description |
array |
The array to copy to. |
arrayIndex |
int 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 The repeated field to compare this with. |
Returns | |
---|---|
Type | Description |
bool |
|
Equals(object)
public override bool Equals(object obj)
Determines whether the specified object, is equal to this instance.
Parameter | |
---|---|
Name | Description |
obj |
object The object to compare with this instance. |
Returns | |
---|---|
Type | Description |
bool |
|
GetEnumerator()
public IEnumerator<T> GetEnumerator()
Returns an enumerator that iterates through the collection.
Returns | |
---|---|
Type | Description |
IEnumerator |
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 |
int |
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 |
int |
The zero-based index of the item, or -1 if it is not found. |
Insert(int, T)
public void Insert(int index, T item)
Inserts the given item at the specified index.
Parameters | |
---|---|
Name | Description |
index |
int 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 |
bool |
|
RemoveAt(int)
public void RemoveAt(int index)
Removes the item at the given index.
Parameter | |
---|---|
Name | Description |
index |
int 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 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 The codec to use when encoding each value. |