Im working on some expression tree code written by a colleague and exploring the possibility of adding additional expressions. It currently supports: equals, not-equals, IsNull, etc. I need to add something that will allow him to use wildcard matching similar to the SQL Like command or using regular expressions. Currently, the code parses the XML file and retrieves the data, which is then processed using code similar to the line shown below. This is an example of the expression "Equal." "callExp" is a MemberExpression expression that basically stores the field name of my table (Entities), and GetConstantExpression gets information about the data I am comparing.
xRet = Expression.MakeBinary(ExpressionType.Equal, callExp, GetConstantExpression(element.Element("Value"), callExp.Type));
That Im after is a way to create an expression similar to the Like command. Can this be done using a few lines similar to the above, or will it be more difficult? Any good resources that can help in this area?
==================================================== ==================================
New Feedback Based Code:
I looked at some examples and tried the following, which I was hoping to create an expression for me. This gives me the error shown below. Am I going in the right direction to create the expression "StartsWith"? _entityExp - ParameterExpression reference to MyClass.
ParameterExpression p = Expression.Parameter(_entityExp.Type, "entity");
MethodInfo method = typeof(string).GetMethod("StartsWith", new[] { typeof(string) });
var containsMethodExp = Expression.Call(p, method, Expression.Constant("root"), p);
The "Boolean StartsWith (System.String)" method declared in type "System.String" cannot be called with an instance of type "MyClass"