The called method receives a parameter of type List<>, which is a custom EC class. I want to construct this List object through reflection

          public  static  object  CreateGeneric(Type generic, Type innerType,  params  object [] args)
         {
             Type specificType = generic.MakeGenericType( new  System.Type[] { innerType });
             return  Activator.CreateInstance(specificType, args);
         }
         object  genericList = CreateGeneric( typeof (List<>),  typeof (EC));
 
 
Get the type of T in List<T>
 
     public  class  MyClass
         {
         }
         Type t =  typeof (List<MyClass>).GetGenericArguments()[0];
         Console.WriteLine(t.Name);
         //输出
          //MyClass
bloodish 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325215174&siteId=291194637