I have a dictionary as follows:
IDictionary<string, string> dict;
How to create an enumerator that implements IDictionaryEnumerator (preferably using linq)?
Must be missing something here, what about:
IDictionary obsoleteDict = dict as IDictionary;
if (obsoleteDict == null)
{
//Do something here...
}
else
{
return obsoleteDict.GetEnumerator();
}
(edit: yep, you have to cast it to the old non-generic interface)
edit2: see Pavel's comment below. A type implementing IDictionary<K,V> may or may not implement IDictionary (Dictionary<K,V> does while some implementations like WCF's MessageProperties do not) so the cast may not work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With