F# library supporting Dynamic Objects including inheritance in functional style. Compatible with Fable javascript and python transpilation.
$ dotnet add package DynamicObjF# library supporting Dynamic Objects including inheritance in functional style.
The library is compatible with Fable, allowing transpilation to javascript and python.
#r "nuget: DynamicObj"
#r "nuget: Fable.Core" // Needed if working with Fable
open DynamicObj
open Fable.Core // Needed if working with Fable
[<AttachMembers>] // AttachMembers needed if working with Fable
type Person(id : int, name : string) =
// Include this in your class
inherit DynamicObj()
let mutable name = name
// Mutable property
member this.Name
with get() = name
and set(value) = name <- value
// Immutable property
member this.ID
with get() = id
let p = Person(1337,"John")
// Access Static Properties
p.GetValue("Name") // val it: obj = "John"
p.GetValue("ID") // val it: obj = 1337
// Overwrite mutable static property
p.SetValue("Name","Jane") // val it: unit = ()
// Overwrite immutable static property
p.SetValue("ID",1234) // System.Exception: Cannot set value for static, immutable property "ID"
// Set dynamic property
p.SetValue("Address","FunStreet") // val it: unit = ()
// Access Properties
p.GetValue("Name") // val it: obj = "Jane"
p.Name // val it: string = "Jane"
p.GetValue("ID") // val it: obj = 1337
p.ID // val it: int = 1337
p.GetValue("Address") // val it: obj = "FunStreet"
DynObj.format p
|> printfn "%s"
->
Name: Jane
ID: 1337
?Address: FunStreet
node --version (Tested with v18.16.1)npm --version (Tested with v9.2.0)dotnet --version (Tested with 7.0.306)py --version (Tested with 3.12.2, known to work only for >=3.11)On windows you can use the setup.cmd to run the following steps automatically!
Setup dotnet tools
dotnet tool restore
Install NPM dependencies
npm install
Setup python environment
py -m venv .venv
Verify correct setup with ./build.cmd runtests ✨