You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
986 B
33 lines
986 B
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace OT.COM.ArsenalDB
|
|
{
|
|
public static class DictionaryExtensions
|
|
{
|
|
// Works in C#3/VS2008:
|
|
// Returns a new dictionary of this ... others merged leftward.
|
|
// Keeps the type of 'this', which must be default-instantiable.
|
|
// Example:
|
|
// result = map.MergeLeft(other1, other2, ...)
|
|
public static T MergeLeft<T, K, V>(this T me, params IDictionary<K, V>[] others)
|
|
where T : IDictionary<K, V>, new()
|
|
{
|
|
T newMap = new T();
|
|
foreach (IDictionary<K, V> src in
|
|
(new List<IDictionary<K, V>> { me }).Concat(others))
|
|
{
|
|
// ^-- echk. Not quite there type-system.
|
|
foreach (KeyValuePair<K, V> p in src)
|
|
{
|
|
newMap[p.Key] = p.Value;
|
|
}
|
|
}
|
|
return newMap;
|
|
}
|
|
|
|
}
|
|
|
|
}
|