Class RepeatedField<T> (3.15.8)

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).

Inheritance

Object > RepeatedField<T>

Implements

IList, IDeepCloneable<RepeatedField<T>>, IEquatable<RepeatedField<T>>, IReadOnlyList<T>

Namespace

Google.Protobuf.Collections

Assembly

Google.Protobuf.dll

Type Parameter

NameDescription
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
TypeDescription
Int32

Count

public int Count { get; }

Gets the number of elements contained in the collection.

Property Value
TypeDescription
Int32

IsReadOnly

public bool IsReadOnly { get; }

Gets a value indicating whether the collection is read-only.

Property Value
TypeDescription
Boolean

Item[Int32]

public T this[int index] { get; set; }

Gets or sets the item at the specified index.

Parameter
NameDescription
indexInt32

The zero-based index of the element to get or set.

Property Value
TypeDescription
T

The element at the specified index.

Methods

Add(T)

public void Add(T item)

Adds the specified item to the collection.

Parameter
NameDescription
itemT

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
NameDescription
valuesIEnumerable<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
NameDescription
inputCodedInputStream

The input stream to read from.

codecFieldCodec<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
NameDescription
ctxParseContext

The input to read from.

codecFieldCodec<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
NameDescription
valuesIEnumerable<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
NameDescription
codecFieldCodec<T>

The codec to use when encoding each field.

Returns
TypeDescription
Int32

The number of bytes that would be written to an output by one of the WriteTo methods, using the same codec.

Clear()

public void Clear()

Removes all items from the collection.

Clone()

public RepeatedField<T> Clone()

Creates a deep clone of this repeated field.

Returns
TypeDescription
RepeatedField<T>

A deep clone of this repeated field.

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)

public bool Contains(T item)

Determines whether this collection contains the given item.

Parameter
NameDescription
itemT

The item to find.

Returns
TypeDescription
Boolean

true if this collection contains the given item; false otherwise.

CopyTo(T[], Int32)

public void CopyTo(T[] array, int arrayIndex)

Copies this collection to the given array.

Parameters
NameDescription
arrayT[]

The array to copy to.

arrayIndexInt32

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
NameDescription
otherRepeatedField<T>

The repeated field to compare this with.

Returns
TypeDescription
Boolean

true if other refers to an equal repeated field; false otherwise.

Equals(Object)

public override bool Equals(object obj)

Determines whether the specified , is equal to this instance.

Parameter
NameDescription
objObject

The to compare with this instance.

Returns
TypeDescription
Boolean

true if the specified is equal to this instance; otherwise, false.

GetEnumerator()

public IEnumerator<T> GetEnumerator()

Returns an enumerator that iterates through the collection.

Returns
TypeDescription
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
TypeDescription
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
NameDescription
itemT

The item to find in the collection.

Returns
TypeDescription
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
NameDescription
indexInt32

The index at which to insert the item.

itemT

The item to insert.

Remove(T)

public bool Remove(T item)

Removes the specified item from the collection

Parameter
NameDescription
itemT

The item to remove.

Returns
TypeDescription
Boolean

true if the item was found and removed; false otherwise.

RemoveAt(Int32)

public void RemoveAt(int index)

Removes the item at the given index.

Parameter
NameDescription
indexInt32

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
TypeDescription
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
NameDescription
outputCodedOutputStream

The output stream to write to.

codecFieldCodec<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
NameDescription
ctxWriteContext

The write context to write to.

codecFieldCodec<T>

The codec to use when encoding each value.