0

I am using dynamic linq and was trying to implement contains logic...I need to return

Func<Expression, Expression, bool, MethodInfo, BinaryExpression>

sample code for equal

private static Func<Expression, Expression, bool, MethodInfo, BinaryExpression> GetFuncForOperand(OperatorType operand)
        {
      case OperatorType.Equal:
                    func = Expression.Equal;
                    break;
                case OperatorType.NotEqual:
                    func = Expression.NotEqual;
                    break;
case Operatortype.Like
//         what should I do
}

how can I express contains ?

BrokenGlass
  • 158,293
  • 28
  • 286
  • 335
charvind
  • 154
  • 2
  • 9
  • 2
    I'm not sure I understand your existing code. Even the code you have doesn't remotely compile. That said, Contains logic would be implemented via a MethodCallExpression, not a BinaryExpression. – Jeff May 24 '11 at 01:42
  • as Jeff pointed out you need a `MethodCallExpression` and an array to perform the `Contains` operation on, have a look at this SO thread for an example: http://stackoverflow.com/questions/278684/how-do-i-create-an-expression-tree-to-represent-string-containsterm-in-c – BrokenGlass May 24 '11 at 01:50
  • I am still trying to wrap my head around expression concept. if some one can quickly code this would be great... I have to deliver something soon... – charvind May 25 '11 at 01:07

1 Answers1

0

Have a look at my blog post, I made my own Like evaluator in c#, complete with unit test.

Kind Contributor
  • 17,547
  • 6
  • 53
  • 70