当重写 DynamicObject 的 TryInvokeMember() 时,如何选择正确的重载来调用?
当重写 DynamicObject
上的以下方法时,您将如何实现算法来选择正确的方法重载?
bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
How would you implement an algorithm to choose the correct method overload, when overriding the following method on DynamicObject
?
bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果此重载问题是由于转发到静态实现的方法造成的。解决方案可能是让 DLR 为您完成工作。开源 Dynamitey 有一个静态方法,可以创建所有 dlr 绑定代码,适当缓存,然后调用它并dlr 绑定器执行重载解析。 示例。此示例在重载决策中处理命名/可选参数和推断泛型,但是 DynamicObject 不会在调用中公开显式泛型或引用参数。
If this overload issue is due to forwarding to statically implemented methods. A solution could be to just let the dlr do the work for you. Open source Dynamitey has a static method that creates all the dlr binding code, caches appropriately and then invokes it and the dlr binder does overload resolution. example. This example handles named/optional params and inferred generics in the overload resolution, however DynamicObject does not expose explict generics or ref out params in the invocation.
这并不简单,因为您必须考虑隐式类型转换和可变长度参数(必须映射到数组)等问题。
MethodCallResolver 类Zentrum 框架中提供了如何查找匹配方法的示例。
It's not straightforward as you have to take into account things like implicit type conversion and variable length parameters (which must be mapped to arrays).
The MethodCallResolver class in the Zentrum framework provides an example of how to find a matching method.