There is a DisplayNameFor(x=>x.Title)
helper in ASP.Net MVC.
I want to implement something similar in behavior.
I want to have a method that accepts an expression based on User
class (u=>u.Birthdate
or u=>u.Name), a operand (Greater, Less, Equal) and a value like DateTime.Now
and returns an expression u=>u.Birthdate > DateTime.Now
I understand that I'll have to build resulting expression manually from pieces. What i can't wrap my head around is passing in and handling of property expression.
Edit:
I want to call a method like
GetFilterPredicate(u=>u.Birthdate,FilterOps.GreaterThan,DateTime.Parse("01.01.2013")
or
GetFilterPredicate(u=>u.SomeIntProperty,FilterOps.Equals,2)
Update: I've created a repo with a solution to this question as well as a collection property filtering https://github.com/Alexander-Taran/Lambda-Magic-Filters
Does this satisfy your needs ?
The below method will produce a binary expression that will have a boolean return value
if you wish for a generic return type just change the
Predicate<TObject>
toFunc<TObject,TReturn>
(You need to replace both occurrences of `Predicate´something like this:
I believe this is what you're aiming for.