考虑以下守则:
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");
顺便说一句,我例外如下:
System.Linq.Dynamic.ParseException was unhandled by user code Message=Operator + incompatible with operand types Vector2 and Vector2 Source=DynamicLINQ Position=6
我怎样才能看到<条码>+条码>操作员在<条码>上超载<2条码>类型?
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.