有没有办法获取参数化泛型类型并获得相应的非参数化类型?
Type parameterizedFoo = typeof(Foo<double>);
Type unparameterizedFoo = parameterizedFoo.TypeWithoutParameters; // == typeof(Foo<>);
答案 0 :(得分:2)
Type unparameterizedFoo = parameterizedFoo.GetGenericTypeDefinition();
答案 1 :(得分:1)
您正在寻找GetGenericTypeDefinition
方法。
Type parameterizedFoo = typeof(Foo<double>);
Type unparameterizedFoo = parameterizedFoo.GetGenericTypeDefinition();
Console.WriteLine(unparameterizedFoo == typeof(Foo<>)); // True