Consider the code below:
var vectorTest = new Vector2(1, 2) + new Vector2(3, 4); // Works
var x = Expression.Parameter(typeof(Vector2), "x");
var test = System.Linq.Dynamic
.DynamicExpression.ParseLambda(new[] { x }, null, "x = x + x");
Running it, I get the exception below:
System.Linq.Dynamic.ParseException was unhandled by user code Message=Operator '+' incompatible with operand types 'Vector2' and 'Vector2' Source=DynamicLINQ Position=6
How do I get the parser to 'see' the +
operator overload on the Vector2
type?
EDIT: I also get the same issue with the =
operator.
Looking at the source I can see why, it looks at a special interface that lists loads of methods, for simple types and if it can't find it, then it raises the exception. Trouble is, my type (Vector2
) isn't in that list, so it won't ever find the operator methods.