I am working on some expression tray codes written by a colleague and I see the possibility of adding additional expressions. It currently supports: equal, not equal, IsNull etc. I need to add something which will allow it to use a wildcard comparison similar to SQL "Like" commands or to use regular expressions. The code currently parses an XML file and removes the data which is processed using the same code as the line shown below. This is an example of the "similar" expression "CallExp" is a member expression that basically tells the field name of my table and the gateconstant expression about the data being compared by me.
xRet = Expression.MakeBinary (ExpressionType.Equal, callExp, GetConstantExpression (element.Element ("value"), callExp.Type)); What I am doing is a way of creating an "expression" that is similar to "likes". Is it possible to use some lines like above or is it going to be more complex? Any good resource that can help in this area?
=========================================== ===============================================
New code based on feedback:
I was considering some examples and tried the following which I expected that I would be creating an expression. This gives me the error shown below Do I go in the right direction to create the "start with" expression? _entityExp There is a parameter excerpt reference for MyClass.
parameter expression p = expression. Parameter (_entityExp.Type, "entity"); MethodInfo method = typeof (string) .GetMethod ("StartsWith", new [] {typef (string)}); Var includes MethodExp = expression. Call (P, Law, Expression Constant ("Root"), P); The system can be declared on 'system.string' type 'boolean start up with (system.string)' which can not be called with the type of 'myclass' type < / P>
Expression trees can represent only the functionality of the same type as you get in .NET languages - method call, property valuation etc. The
The closest to which you normally "like" is to string.tartsWith , string.EndsWith or string.Contains < Calling on / code> If you want to deal with regular expressions instead, you would like to use Regex.IsMatch instead. Either way, it is something that has been explained in the methods instead of the "language" of the expression trees.
Without knowing more about how to eat trees of your expression, it is difficult to say what you really should do be your own The "Likes" method that can handle consumer notices and appropriately, for example ... or you can use existing string / rijks methods.
Comments
Post a Comment