Google.Protobuf.Collections.MapField

Representation of a map field in a Protocol Buffer message.

Summary

Details
Template Parameters
TKey
Key type in the map. Must be a type supported by Protocol Buffer map keys.
TValue
Value type in the map. Must be a type supported by Protocol Buffers.

For string keys, the equality comparison is provided by StringComparer.Ordinal.

Null values are not permitted in the map, either for wrapper types or regular messages. If a map is deserialized from a data stream and the value is missing from an entry, a default value is created instead. For primitive types, that is the regular default value (0, the empty string and so on); for message types, an empty instance of the message is created, as if the map entry contained a 0-length encoded value for the field.

This implementation does not generally prohibit the use of key/value types which are not supported by Protocol Buffers (e.g. using a key type of

byte
) but nor does it guarantee that all operations will work in such cases.

The order in which entries are returned when iterating over this object is undefined, and may change in future versions.

Inheritance

Inherits from: Google.Protobuf.IDeepCloneable< T >, IDictionary< TKey, TValue >, IEquatable< MapField< TKey, TValue >>, IDictionary
Direct Known Subclasses:Google.Protobuf.Collections.MapField< TKey, TValue >.Codec.MessageAdapter

Properties

Count
int
Gets the number of elements contained in the map.
IsFixedSize
bool IDictionary.
IsReadOnly
bool
Gets a value indicating whether the map is read-only.
IsSynchronized
bool ICollection.
Keys
ICollection< TKey >
Gets a collection containing the keys in the map.
Keys
ICollection IDictionary.
SyncRoot
object ICollection.
Values
ICollection< TValue >
Gets a collection containing the values in the map.
Values
ICollection IDictionary.
this[TKey key]
TValue
Gets or sets the value associated with the specified key.
this[object key]
object IDictionary.

Public functions

Add(TKey key, TValue value)
void
Adds the specified key/value pair to the map.
Add(IDictionary< TKey, TValue > entries)
void
Adds the specified entries to the map.
AddEntriesFrom(CodedInputStream input, Codec codec)
void
Adds entries to the map from the given stream.
CalculateSize(Codec codec)
int
Calculates the size of this map based on the given entry codec.
Clear()
void
Removes all items from the map.
Clone()
MapField< TKey, TValue >
Creates a deep clone of this object.
ContainsKey(TKey key)
bool
Determines whether the specified key is present in the map.
Equals(object other)
override bool
Determines whether the specified System.Object, is equal to this instance.
Equals(MapField< TKey, TValue > other)
bool
Compares this map with another for equality.
GetEnumerator()
IEnumerator< KeyValuePair< TKey, TValue > >
Returns an enumerator that iterates through the collection.
GetHashCode()
override int
Returns a hash code for this instance.
Remove(TKey key)
bool
Removes the entry identified by the given key from the map.
ToString()
override string
Returns a string representation of this repeated field, in the same way as it would be represented by the default JSON formatter.
TryGetValue(TKey key, out TValue value)
bool
Gets the value associated with the specified key.
WriteTo(CodedOutputStream output, Codec codec)
void
Writes the contents of this map to the given coded output stream, using the specified codec to encode each entry.

Classes

Google.Protobuf.Collections.MapField< TKey, TValue >.Codec

A codec for a specific map field.

Properties

Count

int Count

Gets the number of elements contained in the map.

IsFixedSize

bool IDictionary. IsFixedSize

IsReadOnly

bool IsReadOnly

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

IsSynchronized

bool ICollection. IsSynchronized

Keys

ICollection< TKey > Keys

Gets a collection containing the keys in the map.

Keys

ICollection IDictionary. Keys

SyncRoot

object ICollection. SyncRoot

Values

ICollection< TValue > Values

Gets a collection containing the values in the map.

Values

ICollection IDictionary. Values

this[TKey key]

TValue this[TKey key]

Gets or sets the value associated with the specified key.

Details
Parameters
key
The key of the value to get or set.
Exceptions
KeyNotFoundException
The property is retrieved and key does not exist in the collection.
Returns
The value associated with the specified key. If the specified key is not found, a get operation throws a KeyNotFoundException, and a set operation creates a new element with the specified key.

this[object key]

object IDictionary. this[object key]

Public functions

Add

void Add(
  TKey key,
  TValue value
)

Adds the specified key/value pair to the map.

This operation fails if the key already exists in the map. To replace an existing entry, use the indexer.

Details
Parameters
key
The key to add
value
The value to add.
Exceptions
System.ArgumentException
The given key already exists in map.

Add

void Add(
  IDictionary< TKey, TValue > entries
)

Adds the specified entries to the map.

The keys and values are not automatically cloned.

Details
Parameters
entries
The entries to add to the map.

AddEntriesFrom

void AddEntriesFrom(
  CodedInputStream input,
  Codec codec
)

Adds entries to the map from the given stream.

It is assumed that the stream is initially positioned after the tag specified by the codec. This method will continue reading entries from the stream until the end is reached, or a different tag is encountered.

Details
Parameters
input
Stream to read from
codec
Codec describing how the key/value pairs are encoded

CalculateSize

int CalculateSize(
  Codec codec
)

Calculates the size of this map based on the given entry codec.

Details
Parameters
codec
The codec to use to encode each entry.
Returns

Clear

void Clear()

Removes all items from the map.

Clone

MapField< TKey, TValue > Clone()

Creates a deep clone of this object.

Details
Returns
A deep clone of this object.

ContainsKey

bool ContainsKey(
  TKey key
)

Determines whether the specified key is present in the map.

Details
Parameters
key
The key to check.
Returns
true if the map contains the given key; false otherwise.

Equals

override bool Equals(
  object other
)

Determines whether the specified System.Object, is equal to this instance.

Details
Parameters
other
The System.Object to compare with this instance.
Returns
true if the specified System.Object is equal to this instance; otherwise, false.

Equals

bool Equals(
  MapField< TKey, TValue > other
)

Compares this map with another for equality.

The order of the key/value pairs in the maps is not deemed significant in this comparison.

Details
Parameters
other
The map to compare this with.
Returns
true if other refers to an equal map; false otherwise.

GetEnumerator

IEnumerator< KeyValuePair< TKey, TValue > > GetEnumerator()

Returns an enumerator that iterates through the collection.

Details
Returns
An enumerator that can be used to iterate through the collection.

GetHashCode

override int GetHashCode()

Returns a hash code for this instance.

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

Remove

bool Remove(
  TKey key
)

Removes the entry identified by the given key from the map.

Details
Parameters
key
The key indicating the entry to remove from the map.
Returns
true if the map contained the given key before the entry was removed; false otherwise.

ToString

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.

TryGetValue

bool TryGetValue(
  TKey key,
  out TValue value
)

Gets the value associated with the specified key.

Details
Parameters
key
The key whose value to get.
value
When this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.
Returns
true if the map contains an element with the specified key; otherwise, false.

WriteTo

void WriteTo(
  CodedOutputStream output,
  Codec codec
)

Writes the contents of this map to the given coded output stream, using the specified codec to encode each entry.

Details
Parameters
output
The output stream to write to.
codec
The codec to use for each entry.