/// <summary>
/// 类
/// </summary>
/// <typeparam name="K1"></typeparam>
/// <typeparam name="K2"></typeparam>
/// <typeparam name="V"></typeparam>
public class MultiKeyDictionary<K1, K2, V> : Dictionary<K1, Dictionary<K2, V>>
{
/// <summary>
///
/// </summary>
/// <param name="key1"></param>
/// <param name="key2"></param>
/// <returns></returns>
public V this[K1 key1, K2 key2]
{
get
{
if (!ContainsKey(key1) || !this[key1].ContainsKey(key2))
throw new ArgumentOutOfRangeException();
return base[key1][key2];
}
set
{
if (!ContainsKey(key1))
this[key1] = new Dictionary<K2, V>();
this[key1][key2] = value;
}
}
/// <summary>
///
/// </summary>
/// <param name="key1"></param>
/// <param name="key2"></param>
/// <param name="value"></param>
public void Add(K1 key1, K2 key2, V value)
{
if (!ContainsKey(key1))
this[key1] = new Dictionary<K2, V>();
this[key1][key2] = value;
}
/// <summary>
///
/// </summary>
/// <param name="key1"></param>
/// <param name="key2"></param>
/// <returns></returns>
public bool ContainsKey(K1 key1, K2 key2)
{
return base.ContainsKey(key1) && this[key1].ContainsKey(key2);
}
/// <summary>
///
/// </summary>
public new IEnumerable<V> Values
{
get
{
return from baseDict in base.Values
from baseKey in baseDict.Keys
select baseDict[baseKey];
}
}
}