FSharp.Interop.Dynamic


FSharp.Interop.Dynamic NuGet Status

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

1: 
PM> Install-Package FSharp.Interop.Dynamic

Build Status

Platform

Status

Nuget Deployment

Build status

Mac/Linux/Windows

Action Status

Coverage

codecov Coverage Status

Bleeding edge feed on MyGet

MyGet Pre Release

Usage

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.

Examples:

System.Dynamic

1: 
2: 
3: 
4: 
open FSharp.Interop.Dynamic
let ex1 = ExpandoObject()
ex1?Test<-"Hi"//Set Dynamic Property
ex1?Test //Get Dynamic

MVC ViewBag

1: 
x.ViewBag?Name<-"George"

Dynamitey

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
open FSharp.Interop.Dynamic
open Dynamitey.DynamicObjects

let ComBinder = LateType("System.Dynamic.ComBinder, System.Dynamic, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")

let getPropertyNames (target:obj) =
  seq {
    yield! target.GetType().GetTypeInfo().GetProperties().Select(fun it -> it.Name)
    if (ComBinder.IsAvailable) then
      yield! ComBinder?GetDynamicDataMemberNames(target)
  }

Python Interop

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
open Python.Runtime
open FSharp.Interop.Dynamic
open FSharp.Interop.Dynamic.Operators
do
  use __ = Py.GIL()
  let math = Py.Import(
  math?cos(math?pi ?*? 2) |> printfn 
  let sin = math?sin
  sin 5 |> printfn 
  math?cos(5) ?+? sin(5) |> printfn 

SignalR (.net framework version)

1: 
2: 
3: 
4: 
5: 
open FSharp.Interop.Dynamic
type MyHub =
    inherit Hub
    member x.Send (name : string) (message : string) =
        base.Clients.All?addMessage(name,message) |> ignore

Caveats:

The 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.

Maintainer(s)

The default maintainer account for projects under "fsprojects" is @fsprojectsgit - F# Community Project Incubation Space (repo management)

Multiple items
namespace FSharp

--------------------
namespace Microsoft.FSharp
namespace FSharp.Interop
namespace FSharp.Interop.Dynamic
val ex1 : obj
val ComBinder : obj
val getPropertyNames : target:obj -> seq<'a>
val target : obj
type obj = System.Object
Multiple items
val seq : sequence:seq<'T> -> seq<'T>

--------------------
type seq<'T> = System.Collections.Generic.IEnumerable<'T>
System.Object.GetType() : System.Type
module Operators

from FSharp.Interop.Dynamic
val __ : 'a (requires 'a :> System.IDisposable)
val math : 'a
val cos : value:'T -> 'T (requires member Cos)
val printfn : format:Printf.TextWriterFormat<'T> -> 'T
val sin : value:'T -> 'T (requires member Sin)
Multiple items
val string : value:'T -> string

--------------------
type string = System.String
val ignore : value:'T -> unit
Fork me on GitHub