I have the following piece of code, all works well until I get to the very last line where it fails with the following exception:
Method 'Boolean Contains(System.Linq.Expressions.ConstantExpression)' declared on type 'System.Collections.Generic.List`1[System.Linq.Expressions.ConstantExpression]' cannot be called with instance of type 'System.Guid'
var filter = new List<SomeObj> { new SomeObj { Id = "<guid-string>" }};
var lookupExpression = filter.SetOperand.Select(x => Expression.Constant(Guid.Parse(x.Id))).ToList();
var arrayOfValues = Expression.NewArrayInit(typeof(Guid), lookupExpression);
var arrayType = lookupExpression.GetType();
var containsMethod = arrayType.GetMethod("Contains");
var right = Expression.Call(dataProperty, containsMethod, arrayOfValues);
I think the problem is that dataProperty is read from a dynamically constructed expression which would always be a Guid so when the method executes, it sees this object as a Guid while the method and list are both List. Is there some other way around this?