I am doing the exact same thing as mentioned here:Which mechanism is a better way to extend Dictionary to deal with missing keys and why?
Making a getter to a dictionary that returns a default. It compiles just fine but anyone trying to use it gets a compiler error saying … and no extension method 'ObjectForKey' accepting a first argument of type System.collections.Genericc.Dictionary could be found.
Here is the definition
public static TValue ObjectForKey<TKey,TValue>(this Dictionary<TKey,TValue> dictionary, TKey key)
{
TValue val = default(TValue);
dictionary.TryGetValue(key,out val);
return val;
}
Here is how I try to use it
Dictionary<string,object> dictionary = <stuff>
object val = dictionary.ObjectForKey("some string");
Any thoughts?