【发布时间】:2014-11-13 09:51:29
【问题描述】:
基本上我有这门课
public class MyBase<TEntity> where TEntity : class
{
//Some retrieval stuff
}
我需要这样做
public class MyEntity : MyBase<MyModel>
{
//More Stuff
}
但使用 TypeBuilder
public TypeBuilder CreateTypeBuilder(Type GenericTypeParameter)
{
Type MyGenericTypedBase = ????;
TypeBuilder type = module.DefineType("MyClassName", TypeAttributes.Public, MyGenericTypedBase);
...
return type;
}
提前致谢
请问,如果使用类型生成器生成泛型类型参数,问题是如何获取应该继承的类型
【问题讨论】:
-
你有什么问题?
-
除非我遗漏了什么,否则不会是
Type MyGenericTypedBase = typeof(MyBase<MyModel>)?; -
不好意思,问题是如果泛型类型参数是使用类型生成器生成的并且无法使用 typeof(MyBase
) ,如何获取应该继承的类型
标签: c# c#-4.0 c#-3.0 typebuilder