Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate an instance of an unknown type at runtime?

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;
like image 859
haze4real Avatar asked Nov 12 '09 14:11

haze4real


Video Answer


1 Answers

Is this what are you are thinking?

object result = Convert.ChangeType("4", Type.GetType("System.Int32"));
like image 82
Philip Wallace Avatar answered Oct 06 '22 19:10

Philip Wallace