Can I declare a variable of Type<T> without specifying T at compile time?

.net, assemblies, c#, generics

Solution

the item in the `< >` has to be a type not an object.

my car is an object of the type car so

Car myCar=new Car();

i want a list to keep my cars (objects of type Car) in.

List<Car> myCars = new List<Car>();

And then we add object of type Car to my List.

 myCars.Add(myCar);
 myCars.Add(anotherCar);

Problem

How do I Load the class "MyContent" dynamically ? I have 1 `interface<T>`, 1 abstract generic `class<T>` and 1 class. Check my code out: ``` public interface IMyObjectInterface{ } public abstract MyAbstractObject : IMyObjectInterface{ } public class MyObject : MyAbstractObject{ } public interface IMyContentInterface<T> where T : MyAbstractObject { void MyMethod(); } public abstract MyAbstractContent<T>, IMyContentInterface<T> where T : MyAbstractObject { public abstract void MyMethod(); } public public class MyContent : MyAbstractContent<MyObject> { public override void MyMethod() { //do something } } ``` I am trying but obviously it's not working: ``` IMyObjectInterface obj = (IMyObjectInterface)Assembly.Load("MyAssembly").CreateInstance("MyObject"); IMyContentInterface<obj> content = (IMyContentInterface<obj>)Assembly.Load("MyAssembly").CreateInstance("MyContent"); content.MyMethod(); //assembly and type names are correct ``` If I change `IMyContentInterface<obj>` to `IMyContentInterface<MyObject>`, works : ``` IMyContentInterface<MyObject> content = (IMyContentInterface<MyObject>)Assembly.Load("MyAssembly").CreateInstance("MyContent"); content.MyMethod(); //assembly and type names are correct ``` The problem is that i don't what is going to be my object in the 2nd line, when defining `IMyContentInterface<T>`. Please, does somebody know how to do it in .NET Framework 4.0?

Original source

Related problems