I'm trying to parse string to create Func instance.
public class A
{
public int fieldA { get; private set; }
public bool fieldB { get; private set; }
public List<int> fieldC { get; private set; }
}
Check the condition of the instance of A
class with :
{
"Type" : "A"
"Condition" : "fieldA > 0 && fieldB == true"
}
Of course the format of a string can be modified, for easier parsing.
What I want to create is actually :
Func<A, bool> condition = a => a.fieldA > 0 && a.fieldB == true;
Parsing the condition
string would not be very hard, but since there are so many A
instances, using reflection whenever checking the condition would not be desirable. What I want to do is "construct" this function from string in advance and cache it somewhere, and call cached function when I want to check the condition.
Could you give my any advices?