I'm trying to create a simple way for external programs to get/set variables within my class. What I have is a class with several variable such as this:
class myClass
{
public int one
{
get{ /* get code here */ }
set{ /* set code here */ }
}
}
Rather than just variable 'one' I have close to 100 variables. All are set up the same way with get and set code. What I would like to have is a simple way to get and set the variables. Example: Instead of having to do this:
myClass c = new myClass();
c.one = 5;
I would like to find a way to do something similar to this:
myClass c = new myClass();
c.setVariable("variableName", value);
It would be ideal to have the "variableName" text come from an enum list so that they could be referenced like:
c.setVariable(enumName.varName, value);
I am unsure how to go about this or if it is even possible. As I said i have close to 100 variables which need their own get/set code, but I'd prefer to have only one public get function and one public set function for various reasons.
As I don't think reflection is very efficient, I'd like to avoid it if at all possible.
I've seen other code in C# where something like this is used:
this["variableName"] = value;
However I can't seem to find a way to make this work either...
Dictionaryinstead.