c# - Is it possible to create this linq statement dynamically? -


i'm creating rule validation class - nothing fancy.

i want set properties this:

public int maxloanamount { get; set; } 

the data validated this. _app refers data injected via constructor.

bool maxloanamountvalid {    { return _app.loanamount >= maxloanamount; } } 

i construct if logic test if each of properties set, validate them , return result, try , little more clever that.

i wonder if possible build dynamic expression, when maxloanamount set, add "maxloanamountvalid", , on "maxloanamountvalid , minloanamountvalid" etc.

thanks in advance.

yes, can dynamically build linq expression tree either using .net apis or 1 of several free tools make job easier. can parse string expression, have build string. see links in answer identical question: dynamically build linq lambda expression

if want more "clever" may dynamically current property name in set method using reflection methodbase.getcurrentmethod().name.


Comments