问题描述
我没能找到一个健壮的、通用的 op_Dynamic 实现:谁能给我指点一下?到目前为止,搜索只找到了玩具或特定用途的实现,但我想手头有一个,比如说,在健壮性方面与 C# 的默认静态动态实现进行比较(即处理批次/所有情况,缓存反射调用)(它是自从我查看 C# 的静态动态以来已经有一段时间了,所以如果我对它的能力的断言是错误的,请原谅我).
I've not been able to find a robust, general op_Dynamic implementation: can anyone point me to one? So far searches have only turned up toys or specific purpose implementations, but I'd like to have one on hand which, say, compares in robustness to C#'s default static dynamic implementation (i.e. handle lots / all cases, cache reflection calls) (it's been a while since I've looked at C#'s static dynamic, so forgive me if my assertions about it's abilities are false).
谢谢!
推荐答案
有一个模块 FSharp.Interop.Dynamic,在 nuget 上应该使用 dlr 稳健地处理动态运算符.
There is a module FSharp.Interop.Dynamic, on nuget that should robustly handle the dynamic operator using the dlr.
与现有的许多代码段相比,它有几个优点.
It has several advantages over a lot of the snippets out there.
- 性能它使用 Dynamitey 来实现缓存,并且是一个 .NET 标准库
- 处理返回 void 的方法,如果不丢弃这些结果,您将收到绑定异常.
- dlr 会自动处理函数调用委托返回的情况,这也将允许您对 FSharpFunc 执行相同操作
添加一个 !?前缀运算符来处理在运行时直接调用没有类型的动态对象和函数.
- Performance it uses Dynamitey for the dlr call which implements caching and is a .NET Standard Library
- Handles methods that return void, you'll get a binding exception if you don't discard results of those.
- The dlr handles the case of calling a delegate return by a function automatically, this will also allow you to do the same with an FSharpFunc
Adds an !? prefix operator to handle invoking directly dynamic objects and functions you don't have the type at runtime.
是开源的,Apache license,可以看实现,它包括单元测试 示例案例.
It's open source, Apache license, you can look at the implementation and it includes unit test example cases.
这篇关于寻找健壮的、通用的 op_Dynamic 实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!