F#动态对象访问 [英] F# dynamic object access

查看:168
本文介绍了F#动态对象访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有访问DLR对象的方式(如DynamicObject子类的实例)的成员(属性和方法)在F#类似于C#动态?

Is there a way to access DLR object (eg. DynamicObject subclass instance) members (properties and methods) in F# that is similar to C# dynamic ?

推荐答案

有是现在的NuGet一个模块,它使用DLR来实现动态的运营商。 FSharp.Interop.Dynamic

There is a module now on nuget that uses the dlr to implement the dynamic operator. FSharp.Interop.Dynamic

它有几个好处超过了很多片段在那里的

It has several advantages over a lot of the snippets out there.


  • 性能,它使用的
    相对=nofollow> Dynamitey
  • 把手的方法返回void,你会得到一个结合异常,如果你不抛弃那些结果。

  • DLR的自动处理通过调用一个函数委托回报的情况下,这也将使你做同样与FSharpFunc

  • 添加一个!?前缀运算处理调用直接动态对象和功能,您不必在运行时的类型。

  • Performance it uses Dynamitey for the dlr call which implements caching and is a PCL 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 the basic unit test example cases.

这篇关于F#动态对象访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆