I have an object
instance for which
instance.GetType().GetGenericTypeDefinition() == typeof(Dictionary<,>)
is true. My question is, how can I extract the key-value pairs from this object without actually knowing their generic types? I would like to get something like
KeyValuePair<object, object>. Note that I also know the generic types the dictionary uses at runtime (but not compile-time). I assume some kind of reflection is required?
FOLLOW-UP: Is there a general mechanism to convert an
SomeClass<> (if I know that is the correct type, of course) and thus use it, given that the implementation of the class is not affected by the type of generic arguments?