3

I know how to do this:

    Expression body = Expression.Call(selector.Body, "Contains", null,
        Expression.Constant("cats", typeof(string)));

Since 'contains' returns true/false it's no problem.

However, how do I do IndexOf and see if the result is greater than 5?

    Expression body = Expression.Call(selector.Body, "IndexOf", null,
        Expression.Constant("cats", typeof(string)));
4

1 回答 1

7

With Expression.GreaterThan:

Expression body = 
 Expression.GreaterThan(
   Expression.Call(selector.Body, "IndexOf", null, Expression.Constant("cats")),
   Expression.Constant(5)
 );
于 2013-06-04T10:43:26.030 回答