如何生成一个未知类型在运行时的一个实例? [英] How to generate an instance of an unknown type at runtime?
本文介绍了如何生成一个未知类型在运行时的一个实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经得到了C#中的以下内容:
字符串类型名=System.Int32的;
字符串值=4;
载文应采取两个字符串来生成指定类型的具有指定值的对象...
结果应该是:
对象o = CreateUnknownType(类型名称,值);
...
INT32测试=(Int32)在O;
解决方案
这是什么你在想什么?
对象result = Convert.ChangeType(4,Type.GetType(System.Int32的));
i've got the following in C#:
string typename = "System.Int32";
string value = "4";
theses two strings should be taken to generate an object of the specified type with the specified value...
result should be:
object o = CreateUnknownType(typename, value);
...
Int32 test = (Int32)o;
解决方案
Is this what are you are thinking?
object result = Convert.ChangeType("4", Type.GetType("System.Int32"));
这篇关于如何生成一个未知类型在运行时的一个实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文