Class RepeatedField<T> (3.23.0)

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

Inheritance

object > RepeatedField<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. The new value is less than .

Property Value
TypeDescription
int

Count

public int Count { get; }

Gets the number of elements contained in the collection.

Property Value
TypeDescription
int

IsReadOnly

public bool IsReadOnly { get; }

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

Property Value
TypeDescription
bool

this[int]

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

Gets or sets the item at the specified index.

Parameter
NameDescription
indexint

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

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

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

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

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

The codec to use when encoding each field.

Returns
TypeDescription
int

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

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
bool

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

CopyTo(T[], int)

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

Copies this collection to the given array.

Parameters
NameDescription
array

The array to copy to.

arrayIndexint

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

The repeated field to compare this with.

Returns
TypeDescription
bool

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

Equals(object)

public override bool Equals(object obj)

Determines whether the specified object, is equal to this instance.

Parameter
NameDescription
objobject

The object to compare with this instance.

Returns
TypeDescription
bool

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

Overrides

GetEnumerator()

public IEnumerator<T> GetEnumerator()

Returns an enumerator that iterates through the collection.

Returns
TypeDescription
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
TypeDescription
int

A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.

Overrides

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
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
NameDescription
indexint

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
bool

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

RemoveAt(int)

public void RemoveAt(int index)

Removes the item at the given index.

Parameter
NameDescription
indexint

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
Overrides

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

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

The codec to use when encoding each value.