-
How to translate string to Object
Is there some sort of evaluation function in .Net that will let you take a string and evaluate it as an object?
ex:
//Contact is a custom Object that contains properties for FirstName
//And LastName
Contact c = new Contact( "Alex Banks" );
//This would write the value of the FirstName
//Which in this case is Alex
Response.Write( c.FirstName );
//Now lets say we have a string that looks like this:
string myObjString = "c.FirstName";
//Is there a way to change this string into regular object code
//So that we can use this string to access the value of c.FirstName?
//For example in ActionScript you can say something like this:
var theName = eval(myObjString);
-or-
var theName = eval("c.FirstName');
-or-
var theLastName = eval("c").LastName;
//How can I go about doing something similar in C#.NET?
-
I don't know of any way to evaluate the variable name ("c" in your example), but given an object instance, you can use reflection to access its fields, properties and methods: http://www.codeguru.com/Csharp/Cshar...cle.php/c4257/
Phil Weber
http://www.philweber.com
Please post questions to the forums, where others may benefit.
I do not offer free assistance by e-mail. Thank you!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|