Adding TryGetValue extension method to IReadOnlyDictionary
AlexGirardDev opened this issue · comments
So i noticed that there isn't an extension method for TryGetValue on specfically IReadOnlyDictionary
there is a static method on the dictionary class here that exsists but a extension would be much nicer syntax.
Would you all be open to me submititng a PR to add this extension method?
Could you propose exact API? Or you want just to add this modifier to the method parameter?
Just adding the this
keyword
It can be problematic because of ambiguity with another extension method TryGetValue
in the same class. The second method has this modifier but for IDictionary<K, V>
type. Unfortunately, IDictionary<,>
doesn't derive from IReadOnlyDictionary
. Additing this to another overload causes compilation error for the following code:
Dictionary<int, string> dict = new();
dict.TryGetValue(42); // which one TryGetValue to call?