Add MapField.MergeFrom to merge maps without failing on duplicate keys

This will enable message MergeFrom methods to implement the documented behavior.
pull/10339/head
Jon Skeet 3 years ago
parent a321b050f5
commit 86fa35913d
  1. 15
      csharp/src/Google.Protobuf/Collections/MapField.cs

@ -237,6 +237,21 @@ namespace Google.Protobuf.Collections
}
}
/// <summary>
/// Adds the specified entries to the map, replacing any existing entries with the same keys.
/// The keys and values are not automatically cloned.
/// </summary>
/// <remarks>This method primarily exists to be called from MergeFrom methods in generated classes for messages.</remarks>
/// <param name="entries">The entries to add to the map.</param>
public void MergeFrom(IDictionary<TKey, TValue> entries)
{
ProtoPreconditions.CheckNotNull(entries, nameof(entries));
foreach (var pair in entries)
{
this[pair.Key] = pair.Value;
}
}
/// <summary>
/// Returns an enumerator that iterates through the collection.
/// </summary>

Loading…
Cancel
Save