C#: Get key and value types of non-generic IDictionary at runtime
Posted
by
Yang Zou
on Stack Overflow
See other posts from Stack Overflow
or by Yang Zou
Published on 2012-07-09T02:55:33Z
Indexed on
2012/07/09
3:15 UTC
Read the original article
Hit count: 175
there. I am wondering how I can get the key and value types of a non-generic IDictionary at runtime.
For generic IDictionary, we can use reflection to get the generic arguments, which has been answered here.
But for non-generic IDictionary, for instance, HybridDictionary, how can I get the key and value types? Thanks.
Edit: I may not describe my problem properly. For non-generic IDictionary, if I have HyBridDictionary, which is declared as
HyBridDictionary dict = new HyBridDictionary();
dict.Add("foo" , 1);
dict.Add("bar", 2);
How can I find out the type of the key is string and type of the value is int? Did I make the question clear? Thanks.
© Stack Overflow or respective owner