I am playing with Reflections and stopped with the next problem.
I can't recognize that the object is of the Dictionary<,> Type.
I receive PropertyInfo from Top object, and this property is of Dictionary<,> class for sure.
Then I do the next:
if (pi.PropertyType.IsGenericType && pi.PropertyType == typeof(IDictionary<,>))
if (pi.PropertyType.IsGenericType && pi.PropertyType == typeof(KeyValuePair<,>))
The type in the
PropertyType is a closed generic type (
Dictionary<string, int> for example) where the type parameters are known. You want to check if the type is any
Dictionary<,> (called an open generic type).
You should do:
pi.PropertyType.GetGenericTypeDefinition() == typeof(Dictionary<,>)