|
-
Mar 21st, 2006, 01:21 PM
#1
Thread Starter
New Member
HowTo: Make a string VALUE into a VARIABLE?
I need a way to "translate" a string into a field/variable name?
For example, I have a string with the value of "FirstName" and I want to then programmatically access user.FirstName
How would I do this?
In C, I'd use pointers, but is there a way to do it in C# and .Net?
Any help would be much appreciated!
Thanks in advance.
-
Mar 21st, 2006, 05:45 PM
#2
Re: HowTo: Make a string VALUE into a VARIABLE?
There seems to be have been a spate of questions like this lately. In most cases when people ask how to do this it is just the case that they have designed their app incorrectly. There aren't many situations where doing something like this is genuinely needed. If you are in a situation where it is needed then you need to use reflection. You get a Type object for your object by calling GetType. The Type class has methods to get FieldInfo, PropertyInfo, MethodInfo, etc. objects that you can use to indirectly access members of an instance of that type. In your case you should take a look at the FieldInfo class.
-
Mar 21st, 2006, 06:58 PM
#3
Thread Starter
New Member
Re: HowTo: Make a string VALUE into a VARIABLE?
Thanks for the feedback.
I'll ping the developer further to see whether what they are doing makes sense. This particular developer is usually a reliable one, when it comes to design, so it didn't occur to me to question them on why they needed what they needed.
Thanks for making me double-check!
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
|
Click Here to Expand Forum to Full Width
|