I think my mind is exploding trying to figure out Funcs… If this makes no sense, I apologize, right now it make sense to me but its been a long day already ….
1) Assuming you are given a func which takes in T and outputs a string:
Func<T, string>
Can you transform that into a func that take in a T and returns a bool based on some logic (in this case if the returned string is empty (String.IsNullOrWhiteSpace)?
Func<T, bool>
2) Can you do the same thing if you are given an
Expression<Func<T, string>>
and need to convert it to a
Func<T, bool>
that returns true/false based on if the returned string is empty (String.IsNullOrWhiteSpace)?
Thanks
for the first part you can even make some "higher"-order function:
use with
(I hope C# type type inference is working here)
If you define this as extension on Func it gets even easier:
here is a very simple test:
For the second one: I think you can compile the expression into a "real" Func and then use the above code. see MSDN Docs on Expression.Compile
PS: renamed the function to better match it’s intend (it’s function composition)