Expression<Func<T, object>>
selector is the selector which I have as a parameter.
My method is a generic type and lets say that I want to get multpile property values form the class for which is being called.
a =>a.customername
is what is being passed to the expression.Please explain, is it possible to have multiple selections ?
like for example I want the customer address also, both are string values.
If you want to get multiple properties out, you could use multiple parameters, where each extracted a single value, but it would be more common to use a lambda expression which creates an anonymous type. For example:
var result = Foo.SomeMethod(customer => new { customer.Name, customer.Address });
The compiler will generate a type with Name
and Address
properties, and create an expression tree which creates an instance of that type using the properties in the Customer
object provided.
See more on this question at Stackoverflow