Q:

Create Numeric Contain Expression with reflection in c#?

We wanna create a linq expression for entity framework as the follows :
//assume numericList is List<int>
entity => numericList.Contain(entity.Id);

we did it as the follows :
// propertType = {Name = "Int32" FullName = "System.Int32"}
// propertyInfo = {Int32 Serial}
// parameterExpression = {entity}
MemberExpression leftSile = Expression.Property(parameterExpression, propertyInfo);
Type listType = typeof (ICollection<>);
Type numbericGenericType = listType.MakeGenericType(propertType);
var valueObject = JsonConvert.DeserializeObject("[1,2,3,4,5]", numbericGenericType);
MethodInfo iListMethodInfo = numbericGenericType.GetMethod("Contains", new[] { propertType });
List<Expression> expressions = new List<Expression>();
foreach (object item in valueObject as ICollection)
    expressions.Add(Expression.Constant(item));
result = Expression.Call(leftSile, iListMethodInfo, expressions); // Exception

It's OK, but the following exception has occurred :
An unhandled exception of type 'System.ArgumentException' occurred in System.Core.dll

Additional information: Method 'Boolean Contains(Int32)' declared on type 'System.Collections.Generic.ICollection`1[System.Int32]' cannot be called with instance of type 'System.Int32'

How can we do it? 
Whats wrong with our codes ?

A:

Your code is incorrect because it tries to construct this call:
 entity.Id.Contains(1, 2, 3, 4, 5)

The first parameter of Expression.Call represents the object on which you call the method. It should be an expression that represents a collection, not your leftSide expression, which is entity.Id. On top of that, the number of parameters does not match, but C# does not report it because the left side is wrong.
In addition, you do not have an expression that represents a collection, you have a collection with a bunch of expressions. You could construct such collection as a constant expression, like this:
Expression collection = Expression.Constant(valueObject); // This replaces the loop

Now you can make an expression like this:
result = Expression.Call(collection, iListMethodInfo, leftSile);

