From 2e7014293430ee42aa25b5edbedb14d9412a92d0 Mon Sep 17 00:00:00 2001 From: Steve Bjorg Date: Thu, 30 Jul 2015 10:43:53 -0700 Subject: [PATCH] Copied over methods from Deki that should be available in DReAM instead. --- .../Collections/Generic/DictionaryUtil.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/mindtouch.dream/system/Collections/Generic/DictionaryUtil.cs b/src/mindtouch.dream/system/Collections/Generic/DictionaryUtil.cs index 4b0ce56..7eeca7d 100644 --- a/src/mindtouch.dream/system/Collections/Generic/DictionaryUtil.cs +++ b/src/mindtouch.dream/system/Collections/Generic/DictionaryUtil.cs @@ -39,5 +39,34 @@ public static Dictionary ToDictionaryWithDuplicateErrorCallback(t } return result; } + + public static IEnumerable CollectAllValues(this IDictionary> dictionary, IEnumerable keys, out IEnumerable missing) { + var result = new List(); + var missingResult = new List(); + foreach(var key in keys) { + ICollection value; + if(dictionary.TryGetValue(key, out value)) { + result.AddRange(value); + } else { + missingResult.Add(key); + } + } + missing = missingResult; + return result; + } + + public static Dictionary ToDictionary(this IEnumerable> source, bool overwriteDuplicates = false) { + var result = new Dictionary(); + if(overwriteDuplicates) { + foreach(var pair in source) { + result[pair.Key] = pair.Value; + } + } else { + foreach(var pair in source) { + result.Add(pair.Key, pair.Value); + } + } + return result; + } } }