【发布时间】:2020-09-14 15:20:10
【问题描述】:
请告诉我如何确定在继承期间传递给参数泛型的类型
public abstract class BaseEntity
{
}
public class DogEntity : BaseEntity
{
}
public interface IAnimal
{
}
public abstract class Animal<TEntity> : IAnimal
where TEntity : BaseEntity
{
}
public class Dog : Animal<DogEntity>
{
}
我只有 Dog 实体类型,我需要获取 DogEntity
Type type = typeof(Dog);
如果有任何帮助或提示,我将不胜感激
【问题讨论】:
-
typeof(Dog).BaseType.GenericTypeArguments[0];或许可以,但我在手机上,所以无法测试
标签: c# .net inheritance reflection