A
AdamM
At runtime, how do you take a user-supplied string, and then match that up
with a class property name?
For example, I have a User class with the property User.Name. At runtime, I
want the user to type 'set user.name=adam' and the code checks the user
class instance for the property name provided (Name) and assigns that value?
I cannot figure out how to do this without hardcoding the "set" code to know
the Name property in advance. As you can see, with every addition to the
User class, it would require changing the "set" code accordingly. I am
trying to avoid that by writing code that can figure out what properties are
available on a given class at runtime and interacting with them based on
user input.
Any tips? Thanks!
with a class property name?
For example, I have a User class with the property User.Name. At runtime, I
want the user to type 'set user.name=adam' and the code checks the user
class instance for the property name provided (Name) and assigns that value?
I cannot figure out how to do this without hardcoding the "set" code to know
the Name property in advance. As you can see, with every addition to the
User class, it would require changing the "set" code accordingly. I am
trying to avoid that by writing code that can figure out what properties are
available on a given class at runtime and interacting with them based on
user input.
Any tips? Thanks!