Expression.Call() to String.Equals() throws error

Posted by Sam on Stack Overflow See other posts from Stack Overflow or by Sam
Published on 2010-03-16T01:19:34Z Indexed on 2010/03/16 1:29 UTC
Read the original article Hit count: 284

Filed under:
|

The following code:

var constant = Expression.Constant("find me", typeof(string));

// memberExpression evaluates to a string
var predicate = Expression.Call(memberExpression, "Equals", null, constant);

is throwing the error More than one method 'Equals' on type 'System.String' is compatible with the supplied arguments.

I'm guessing that's because there's Equals(Object) and Equals(String) - is there any way for me to specify which method I mean to use via the overload of Expression.Call() that takes an instance method name as a string?

Or do I have to make a special case for calls to Equals() to take a MethodInfo instead?

© Stack Overflow or respective owner

Related posts about LINQ

Related posts about c#