Is there a way to access DLR object (eg. DynamicObject subclass instance) members (properties and methods) in F# that is similar to C# 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.
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 the dynamic
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With