Assume I have an generic type of an runtime object and a raw generic type of the same class, e.g.
var type = (new List<Int32>()).GetType();
var genericListType = typeof(List<>);
I need kind of GetRawGenericType method, so the expression
GetRawGenericType(type) == genericListType
returns true. Is there a way to implement this ?
Remarks:
I do not know the type of the of the object it may be any generic type.
In the code I’m writing I have to know the exact generic type as it will be used as a key in a Dictionary, for example :
private readonly Dictionary<Type, TValue> Mapping =
new Dictionary<Type, TValue> {
{typeof(IEnumerable<>), *SomeValue*},
...
}
Thanks in advance for you time spend.
Type.GetGenericTypeDefinitionis what you looking for.