I'm trying to write an extension method to insert data into a dictionary of dictionaries defined as follows:
items=Dictionary<long,Dictionary<int,SomeType>>()
What I have so far is:
public static void LeafDictionaryAdd<TKEY1,TKEY2,TVALUE>(this IDictionary<TKEY1,IDictionary<TKEY2,TVALUE>> dict,TKEY1 key1,TKEY2 key2,TVALUE value)
{
var leafDictionary =
dict.ContainsKey(key1)
? dict[key1]
: (dict[key1] = new Dictionary<TKEY2, TVALUE>());
leafDictionary.Add(key2,value);
}
but the compiler doesn't like it. The statement:
items.LeafDictionaryAdd(longKey, intKey, someTypeValue);
gives me a type inference error.
For the statement:
items.LeafDictionaryAdd<long, int, SomeType>(longKey, intKey, someTypeValue);
I get "...does not contain a definition for... and the best extension method overload has some invalid arguments.
What am I doing wrong?