Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Runtime/Google.Protobuf/Collections/MapField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,32 @@ public sealed class MapField<TKey, TValue> : IDeepCloneable<MapField<TKey, TValu
new Dictionary<TKey, LinkedListNode<KeyValuePair<TKey, TValue>>>(KeyEqualityComparer);
private readonly LinkedList<KeyValuePair<TKey, TValue>> list = new LinkedList<KeyValuePair<TKey, TValue>>();

/// <summary>
/// Merges entries from an <see cref="IDictionary{TKey, TValue}"/> into this instance.
/// </summary>
/// <param name="other">
/// The dictionary whose entries will be merged into this map.
/// </param>
public void MergeFrom(IDictionary<TKey, TValue> other)
{
foreach (var kv in other)
{
this[kv.Key] = kv.Value;
}
}

/// <summary>
/// Merges entries from another <see cref="MapField{TKey, TValue}"/> into this instance.
/// </summary>
/// <param name="other">
/// The <see cref="MapField{TKey, TValue}"/> whose entries will be merged.
/// </param>
public void MergeFrom(MapField<TKey, TValue> other)
{
// Reuse the IDictionary<TKey, TValue> MergeFrom implementation
MergeFrom((IDictionary<TKey, TValue>)other);
}

/// <summary>
/// Creates a deep clone of this object.
/// </summary>
Expand Down