使用Reflection:
//创建对象
Type elType = Type.GetType(T);
Type genType = typeof(GenericType<>).MakeGenericType(elType);
object obj = Activator.CreateInstance(genType);
//调用对象的方法
MethodInfo method = genType.GetMethod("MethodName",BindingFlags.Instance | BindingFlags.Public);
method.Invoke(obj,null);
网友评论