C# Reference Map Fields

1,095 views
Skip to first unread message

Tung Tran

unread,
Nov 12, 2019, 6:25:23 PM11/12/19
to Protocol Buffers
Hi guys,

Just to clarify a point in the following documentation:

Map Fields

Each map field generates a read-only property of type Google.Protobuf.Collections.MapField<TKey, TValue> where TKey is the field's key type and TValue is the field's value type. For the most part, this acts like Dictionary<TKey, TValue>, but it has an additional Add overload to allow another dictionary to be added in one go. This is convenient when populating a repeated field in an object initializer. Additionally, MapField<TKey, TValue> has direct support for serialization, deserialization and cloning, but this is usually used by generated code instead of manually-written application code. Keys in the map are not permitted to be null; values may be if the corresponding singular field type would support null values.



https://developers.google.com/protocol-buffers/docs/reference/csharp/class/google/protobuf/collections/map-field-t-key-t-value-


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.




My question is: Can the value in MapFields be null or not? The generated implementation prohibits it but I want to make sure that it is the case. 



Thanks

Tung


My apologies if someone else have already posted the same question. I was unable to search for an topic about this.

Reply all
Reply to author
Forward
0 new messages