I want to create simple factory class which implements interface like this:
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>();
Is it possible? Does interface is correct?
I've tried something like this:
private TEntity CreateEmpty<TEntity>() {
var type = typeof(TEntity);
if(type.Name =="TestClass") {
return new TestClass();
}
else {
...
}
}
But it doesn't compile.