Is there a way to access DLR object (eg. DynamicObject subclass instance) members (properties and methods) in F# that is similar to C# dynamic ?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Generic Generics in Managed C++
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
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.
Adds an !? prefix operator to handle invoking directly dynamic objects and functions you don't have the type at runtime.
It's open source, Apache license, you can look at the implementation and the basic unit test example cases.
As eriawan mentioned, the
?
operator behaves a bit like thedynamic
type in C#. The article about calling SQL doesn't rely on anything from the DLR, because you can provide your own implementation of the?
operator and the compiler uses it directly.I also wrote a brief example of how to use the
?
operator to call members using DLR, which is available on F# snippets and there is a more sophisticated version by Matthew Podwysocki. Another snippet shows how to use it to call standard .NET types using Reflection.See also:
Yes, it is. You can use
?
operator in F#, and it will perform the same way in dynamic typing in C# and VB.NET in .NET 4.0. For a start, you can read this sample Dynamic SQLDataReader from Tomas Petricek's blog:http://tomasp.net/blog/dynamic-sql.aspx
Here's a quote from his article:
And for more info, you can read the rest of his article. Happy dynamic coding in F# :)