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

10/17 11:15
阅读数 0

问题:

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
展开阅读全文
got
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部