mercredi 22 juillet 2015

Get Object from its name

I have an object:

MyObject obj = new MyObject();
obj.X = "Hello";
obj.Y = "World";

Someone passes me a string:

string myString = "obj.X";

I want to get the value referenced to myString, like this:

var result = <Some Magic Expression>(myString); // "Hello"    

Is it possible through reflection?





Aucun commentaire:

Enregistrer un commentaire