I am 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 still have:
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 he doesnβt like the compiler. Statement:
items.LeafDictionaryAdd(longKey, intKey, someTypeValue);
gives me a type inference error.
For approval:
items.LeafDictionaryAdd<long, int, SomeType>(longKey, intKey, someTypeValue);
I get: "... does not contain a definition for ... and the best way to overload the extension method has some invalid arguments.
What am I doing wrong?
source share