I have a issue where I want to identify if a object is of type KeyValuePair<,>
when I compare in if:
else if (item.GetType() == typeof(KeyValuePair<,>))
{
var key = item.GetType().GetProperty("Key");
var value = item.GetType().GetProperty("Value");
var keyObj = key.GetValue(item, null);
var valueObj = value.GetValue(item, null);
...
}
this is false as IsGenericTypeDefinition
is different for them.
Can someone explain me why this is happening and how to solve the this issue in correct way (I mean not comparing Names or other trivial fields.)
THX in advance!