English 中文(简体)
动态支线和运营商超负荷
原标题:Dynamic linq and operator overloads

考虑以下守则:

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.

最佳回答

与Linq图书馆合作,请在<编码>发现的签字接口之一上添加签名。 System.Linq.Dynamic.ExpressionParser 。 它只能控制它承认的行动。

它似乎将研究在<代码>ExpressionParser上发现的所有私人接口。 在<代码>ExpressionParser内添加一个接口,似乎可以消除这一错误。

interface ICustomSignatures
{
    void F(Microsoft.Xna.Framework.Vector2 x, Microsoft.Xna.Framework.Vector2 y);
}

仅仅为了安全(并可能符合预期的模式),添加/扩充<代码>可能更为安全。 IAddSignatures >。

interface ICustomSignatures : IAddSignatures
{
    void F(Microsoft.Xna.Framework.Vector2 x, Microsoft.Xna.Framework.Vector2 y);
}
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签