samedi 16 mai 2015

Generics class from a runtime type

i have a class that build in runtime (RClass) and also have a Generic class B, how can i create a type of DataLoader and use its method.

public interface IDataLoader<GType>
{
//some code
   GType SampleMethod();
}

public class DataLoader <GType>: IDataLoader<GType>
{
  GType SampleMethod(){
    //some code
  }
}

//class "RClass" created in runtime
MyClassBuilder MCB=new MyClassBuilder("RClass");
var myclass = MCB.CreateObject(new string[3] { "id", "name", "link" }, new Type[3] { typeof(int), typeof(string), typeof(string) });
Type myclassType = myclass.GetType();

var dta = typeof(DataLoader<>).MakeGenericType(myclassType);
// ?????
var gs = (???)Activator.CreateInstance(dta);
gs.SampleMethod();





Aucun commentaire:

Enregistrer un commentaire