Best way to translate from IDictionary to a generic IDictionary

Posted by George Mauer on Stack Overflow See other posts from Stack Overflow or by George Mauer
Published on 2010-06-02T22:13:28Z Indexed on 2010/06/02 22:24 UTC
Read the original article Hit count: 349

Filed under:
|

I've got an IDictionary field that I would like to expose via a property of type IDictionary<string, dynamic> the conversion is surprisingly difficult since I have no idea what I can .Cast<>() the IDictionary to.

Best I've got:

IDictionary properties;
protected virtual IDictionary<string, dynamic> Properties {
  get { 
        return _properties.Keys.Cast<string>()
              .ToDictionary(name=>name, name=> _properties[name] as dynamic); 
      }
    }

© Stack Overflow or respective owner

Related posts about c#

Related posts about generics