I have created an expression like:
expression = x => x.CustomerName.StartsWith(comboParams.ParamValueText, true, null);
I would like access customer name as generic something like this:
expression = x => x["CustomerName"] and access the StartsWith function
I have already tried code such as
expression x => x.GetType().GetProperty("CustomerName").Name.StartsWith(comboParams.ParamValueText, true, null); --> it doesn't seem to work :(
Is there a way to accomplish this task. I’m making this to have a common implementation for the expression, maybe I’ll create a function for this and just accept the string. Thanks!
The problem with your code is that
x.GetType().GetProperty("CustomerName").Namewill return the name of the property not the value of it.You need the following code.