我想要创建简单的工厂级,实施这样的接口:
IFactory
{
TEntity CreateEmpty<TEntity>();
}
In this method I want to return an instance of type TEntity (generic type). Example:
TestClass test = new Factory().CreateEmpty<TestClass>();
是否可能? 接口是否正确?
我试图这样做:
private TEntity CreateEmpty<TEntity>() {
var type = typeof(TEntity);
if(type.Name =="TestClass") {
return new TestClass();
}
else {
...
}
}
但它没有汇编。