summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Matusewicz <matekm@gmail.com>2016-11-17 09:37:43 +0000
committerRobert Matusewicz <matekm@gmail.com>2016-11-19 10:59:36 +0000
commite08c2d4bdaf5e211a31303f271a4f11b2223ad7a (patch)
tree0911c5e74efbadc568534e3da0dec46e66572979
parentc48d0320f6bccc9da93b5aefb576f0ac2692c446 (diff)
downloadcoreclr-e08c2d4bdaf5e211a31303f271a4f11b2223ad7a.tar.gz
coreclr-e08c2d4bdaf5e211a31303f271a4f11b2223ad7a.tar.bz2
coreclr-e08c2d4bdaf5e211a31303f271a4f11b2223ad7a.zip
Add System.Collections.Generic.Dictionary constructor that accepts
IEnumerable<KeyValyePair<TKey, TValue>> to initialize dictionary
-rw-r--r--src/mscorlib/model.xml2
-rw-r--r--src/mscorlib/ref/mscorlib.cs2
-rw-r--r--src/mscorlib/src/System/Collections/Generic/Dictionary.cs15
3 files changed, 19 insertions, 0 deletions
diff --git a/src/mscorlib/model.xml b/src/mscorlib/model.xml
index 115d8959ee..7fa31fbd93 100644
--- a/src/mscorlib/model.xml
+++ b/src/mscorlib/model.xml
@@ -644,6 +644,8 @@
<Member Name="#ctor" />
<Member Name="#ctor(System.Collections.Generic.IDictionary&lt;TKey,TValue&gt;)" />
<Member Name="#ctor(System.Collections.Generic.IDictionary&lt;TKey,TValue&gt;,System.Collections.Generic.IEqualityComparer&lt;TKey&gt;)" />
+ <Member Name="#ctor(System.Collections.Generic.IEnumerable&lt;System.Collections.Generic.KeyValuePair&lt;TKey,TValue&gt;&gt;)" />
+ <Member Name="#ctor(System.Collections.Generic.IEnumerable&lt;System.Collections.Generic.KeyValuePair&lt;TKey,TValue&gt;&gt;,System.Collections.Generic.IEqualityComparer&lt;TKey&gt;)" />
<Member Name="#ctor(System.Collections.Generic.IEqualityComparer&lt;TKey&gt;)" />
<Member Name="#ctor(System.Int32)" />
<Member Name="#ctor(System.Int32,System.Collections.Generic.IEqualityComparer&lt;TKey&gt;)" />
diff --git a/src/mscorlib/ref/mscorlib.cs b/src/mscorlib/ref/mscorlib.cs
index 18898b8dc5..da378777c9 100644
--- a/src/mscorlib/ref/mscorlib.cs
+++ b/src/mscorlib/ref/mscorlib.cs
@@ -4473,6 +4473,8 @@ namespace System.Collections.Generic
public Dictionary() { }
public Dictionary(System.Collections.Generic.IDictionary<TKey, TValue> dictionary) { }
public Dictionary(System.Collections.Generic.IDictionary<TKey, TValue> dictionary, System.Collections.Generic.IEqualityComparer<TKey> comparer) { }
+ public Dictionary(System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>> collection) { }
+ public Dictionary(System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>> collection, System.Collections.Generic.IEqualityComparer<TKey> comparer) { }
public Dictionary(System.Collections.Generic.IEqualityComparer<TKey> comparer) { }
public Dictionary(int capacity) { }
public Dictionary(int capacity, System.Collections.Generic.IEqualityComparer<TKey> comparer) { }
diff --git a/src/mscorlib/src/System/Collections/Generic/Dictionary.cs b/src/mscorlib/src/System/Collections/Generic/Dictionary.cs
index 25b9c384d4..2bbe7f9424 100644
--- a/src/mscorlib/src/System/Collections/Generic/Dictionary.cs
+++ b/src/mscorlib/src/System/Collections/Generic/Dictionary.cs
@@ -129,6 +129,21 @@ namespace System.Collections.Generic {
}
}
+ public Dictionary(IEnumerable<KeyValuePair<TKey, TValue>> collection):
+ this(collection, null) { }
+
+ public Dictionary(IEnumerable<KeyValuePair<TKey, TValue>> collection, IEqualityComparer<TKey> comparer):
+ this((collection as ICollection<KeyValuePair<TKey, TValue>>)?.Count ?? 0, comparer)
+ {
+ if (collection == null) {
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection);
+ }
+
+ foreach (KeyValuePair<TKey, TValue> pair in collection) {
+ Add(pair.Key, pair.Value);
+ }
+ }
+
protected Dictionary(SerializationInfo info, StreamingContext context) {
//We can't do anything with the keys and values until the entire graph has been deserialized
//and we have a resonable estimate that GetHashCode is not going to fail. For the time being,