Possible Duplicate:
Can I declare a variable of Type<T> without specifying T at compile time?
Objective: To Load the class "MyContent" dynamically. I have 1 interface<T>
, 1 abstract generic class<T>
.
Code:
public interface IMyObjectInterface{
}
public abstract MyAbstractObject : IMyObjectInterface{
}
public class MyObject : MyAbstractObject{
}
public interface IMyContentInterface<T> where T : MyAbstractObject
{
T MyMethod();
void MyMethod2(T);
}
public abstract MyAbstractContent<T>, IMyContentInterface<T> where T : MyAbstractObject
{
public abstract T MyMethod();
public abstract void MyMethod2(T);
}
public class MyContent : MyAbstractContent<MyObject>
{
public override MyObject MyMethod() { //do something with MyObject }
public override void MyMethod2(MyObject) { //do something with MyObject }
}
Now, we load:
IMyObjectInterface obj = (IMyObjectInterface)Assembly.Load("MyAssembly").CreateInstance("MyObject");
IMyContentInterface<???> content = (IMyContentInterface<???>)Assembly.Load("MyAssembly").CreateInstance("MyContent");
content.MyMethod();
How to load ???