I need to detect whether an object of type IDictionary<string, string> is an IDictionary<,> and I’m having trouble coming up with the proper comparison logic.
I have tried the following:
typeof(IDictionary<string, string>)
.GetInterface(typeof(IDictionary<,>).Name);
and
typeof(IDictionary<string, string>)
.GetGenericTypeDefinition()
.GetInterface(typeof(IDictionary<,>).Name);
Calling typeof(Dictionary<string,string>).GetInterface(comparisonType.Name) returns the expected non-null result, but if I compare on the IDictionary<string,string> type, GetInterface() returns null. Likewise, comparing on the GenericTypeDefinition also returns null.
1 Answer