Is it possible to assign a variable to an expression in C# so that I don't have to write a method for it? For example, a variable named canBuild be equal to an expression "numResources > 50". And whenever that variable is called, it recalculates it's value. I've tried looking into lambdas but I don't really understand the documentation.
Thank you
EDIT:
Here's an attempt I tried with using lamdas:
public void setStateFloat(float variable, float comparison, int compareType)
{
Func<bool> stateEval;
switch(compareType)
{
case 0:
stateEval = () => variable < comparison;
break;
case 1:
stateEval = () => variable > comparison;
break;
case 2:
stateEval = () => variable == comparison;
break;
}
}
Will this work if variable and comparison are not local to the object using this function (as in an object referring to another objects variable). I doubt it since it will only be a copy of the variable and not a pointer/reference to the where the original variable is stored.
Also, if I wanted to store a reference to the function, how would I do that?
The reason behind this is that I am developing a highly structured and modular system for designers and one of the requirements is creating a function from their input that are calculated initially and then used during runtime. Alternative approaches are welcome.
Kind thanks.