diff options
author | Robert Matusewicz <matekm@gmail.com> | 2016-11-17 09:37:43 +0000 |
---|---|---|
committer | Robert Matusewicz <matekm@gmail.com> | 2016-11-19 10:59:36 +0000 |
commit | e08c2d4bdaf5e211a31303f271a4f11b2223ad7a (patch) | |
tree | 0911c5e74efbadc568534e3da0dec46e66572979 /src/mscorlib/src/System/Collections | |
parent | c48d0320f6bccc9da93b5aefb576f0ac2692c446 (diff) | |
download | coreclr-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
Diffstat (limited to 'src/mscorlib/src/System/Collections')
-rw-r--r-- | src/mscorlib/src/System/Collections/Generic/Dictionary.cs | 15 |
1 files changed, 15 insertions, 0 deletions
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, |