【发布时间】:2020-03-12 17:29:41
【问题描述】:
考虑类:
public class Super : Base<Test, Super>
{
public Super Next { get; set; }
}
public class Base<TArg, TSuper>
{
public Type GetTestArgument()
{
Type[] arguments = typeof(TSuper).GetProperty("Next").PropertyType.BaseType.GetGenericTypeDefinition().GetGenericArguments();
// arguments is set to [ TArg, TSuper ] instead of [ Test, Super ]
return arguments[0]; // should be Test
}
}
有谁知道如何在不调用typeof(TArg) 的情况下从基类中获取泛型类型,因为我将遍历其他超类属性,并且必须通过更深层次的反射。
谢谢。
【问题讨论】:
-
typeof(TArg)? -
@Amy 我编辑添加了我忘记的信息。不过还是谢谢。
标签: c# inheritance reflection