Pass An Instantiated System.Type as a Type Parameter for a Generic Class

问题:

The title is kind of obscure.标题有点晦涩。 What I want to know is if this is possible:我想知道的是这是否可能:

string typeName = <read type name from somwhere>;
Type myType = Type.GetType(typeName);

MyGenericClass<myType> myGenericClass = new MyGenericClass<myType>();

Obviously, MyGenericClass is described as:显然,MyGenericClass 被描述为:

public class MyGenericClass<T>

Right now, the compiler complains that 'The type or namespace 'myType' could not be found." There has got to be a way to do this.现在,编译器抱怨“找不到类型或命名空间‘myType’。”必须有办法做到这一点。


解决方案:

参考一: https://en.stackoom.com/question/17EB
参考二: https://stackoom.com/question/17EB
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章