The F# Dynamic Operator, powered by the DLR. Compiled for .NET Standard 2.0, .NET Standard 1.6, .NET Framework 4.5
Install from NuGet
PM> Install-Package FSharp.Interop.Dynamic
| Platform | Status |
|---|---|
| Nuget Deployment | |
| Mac/Linux/Windows | |
| Coverage |
target?Property, target?Property<-value, and target?Method(arg,arg2) allow you to dynamically get/set properties and call methods
Also Dyn.implicitConvert,Dyn.explicitConvert, comparison operators and more.
openFSharp.Interop.Dynamicletex1= ExpandoObject()
ex1?Test<-"Hi"//Set Dynamic Property
ex1?Test //Get Dynamicx.ViewBag?Name<-"George"openFSharp.Interop.DynamicopenDynamitey.DynamicObjectsletComBinder= LateType("System.Dynamic.ComBinder, System.Dynamic, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")letgetPropertyNames(target:obj)=seq{yield! target.GetType().GetTypeInfo().GetProperties().Select(fun it -> it.Name)if(ComBinder.IsAvailable)thenyield! ComBinder?GetDynamicDataMemberNames(target)}Translated from this example C# code: https://github.com/SciSharp/pythonnet#example
openPython.RuntimeopenFSharp.Interop.DynamicopenFSharp.Interop.Dynamic.Operatorsdouse __ = Py.GIL()letnp= Py.Import("numpy")
np?cos(np?pi ?*?2)|> printfn "%O"letsin:obj ->obj = np?sin
sin 5|> printfn "%O"
np?cos 5?+? sin 5|> printfn "%O"leta:obj = np?array([|1.;2.;3.|])
printfn "%O" a?dtype
letb:obj = np?array([|6.;5.;4.|], Dyn.namedArg "dtype" np?int32)
printfn "%O" b?dtype
a ?*? b
|> printfn "%O"Output
1.0
-0.9589242746631385
-0.6752620891999122
float64
int32
[ 6. 10. 12.]
openFSharp.Interop.DynamictypeMyHub=inherit Hub
memberx.Send(name :string)(message :string)=base.Clients.All?addMessage(name,message)|> ignoreThe DLR is incompatible with interface explicit members, so are these operators, just like C#'s dynamic keyword.
.NET Core 2.0.0 to 2.0.2 had a major bug in the C# dynamic keyword with nested classes inside of generic classes.. You will know it from a substring argument length exception. .NET Framework 4.0+, .NET Core 1.x and .NET Core 2.0.3+ and later are unaffected.
The default maintainer account for projects under "fsprojects" is @fsprojectsgit - F# Community Project Incubation Space (repo management)