本文介绍了寻找健壮的,通用的op_Dynamic实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法找到一个可靠的,通用的op_Dynamic实现:有人可以指出我一个吗?到目前为止,搜索仅出现了玩具或特定目的的实现,但我想手头上有一个,比起C#的默认静态动态实现(例如,处理很多/所有情况,缓存反射调用),其健壮性高.自从我看过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 ,位于应使用dlr可靠处理动态运算符的nuget上.

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.

  • 性能,它对实现缓存的dlr调用使用 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许可证,您可以查看实现,其中包括单元测试示例案例.

It's open source, Apache license, you can look at the implementation and it includes unit test example cases.

这篇关于寻找健壮的,通用的op_Dynamic实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 05:26