[Name("Admin")]
public class TestAdmin : TestUserBase<TestAdmin>
{
public TestAdmin(Type webDriverType) : base(webDriverType)
{
}
}
目前,我有一堆这种形式的类,我想在运行时使用 Reflection.Emit 创建这些类。但是,当我尝试添加父级时遇到了一个问题 - 因为 TestAdmin 类在运行时之前不存在,所以我不知道如何创建
TestUserBase<TestAdmin>
有什么想法吗?
最佳答案
您可以使用 SetParent 设置父类型:
TypeBuilder tb = mb.DefineType("TestAdmin", TypeAttributes.Public);
tb.SetParent(typeof(TestUserBase<>).MakeGenericType(tb));
Type theType = tb.CreateType();
关于c# - 在 Reflection.Emit 中使用发射类型作为类型参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17032898/