0

First off, sorry if my title doesn't relate to my question. it has been a long day.

Basically, i wanted to know if i can write a class that takes lambda expression and evaluate its condition. IE:

(x=>x.property1 == 1) or x=>x.property1 < 1)

Ultimately, once the expression is passed to my class, I want to be able to evaluate the expression.

I'm trying to add some custom validator into FluentValidation. And my first issue was to be able to parse the lambda expression:

RuleFor(x=>x.Property2).RequiredIF(x=>x.Property1==0)
user1784014
  • 234
  • 1
  • 12

1 Answers1

0

You can create it as extension method and use inside combination of calls:

return When(expression).NotEmpty()

In this way you shouldn't evaluate expression, method When will do it.

David Levin
  • 6,573
  • 5
  • 48
  • 80