Partas.Feliz.Generator 0.5.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Partas.Feliz.Generator --version 0.5.0
                    
NuGet\Install-Package Partas.Feliz.Generator -Version 0.5.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Partas.Feliz.Generator" Version="0.5.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Partas.Feliz.Generator" Version="0.5.0" />
                    
Directory.Packages.props
<PackageReference Include="Partas.Feliz.Generator" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Partas.Feliz.Generator --version 0.5.0
                    
#r "nuget: Partas.Feliz.Generator, 0.5.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Partas.Feliz.Generator@0.5.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Partas.Feliz.Generator&version=0.5.0
                    
Install as a Cake Addin
#tool nuget:?package=Partas.Feliz.Generator&version=0.5.0
                    
Install as a Cake Tool

Partas.Feliz.Generator

This is heavily WIP and currently not suitable for public use outside of contribution/testing

A simple cool stupid generator using Fantomas and a previous script I made for refining Glultinum bindings.

Allows us to use a fsx script as a source of truth, with a simplified scheme of defining Feliz bindings, and then generating the file from that.

Goals

Maximize lazy cat vibes.

The 'DSL' is simply supposed to require less effort than manually creating the bindings. It can also be used as an intermediary for formats like yaml, or others.

Current API

API is constantly changing, check the tests to see what does what until I settle on something

// The definition of a file is done by building a schema
type Schema = {
    // Manipulate how things are generated
    Config: Config
    // The namespace for the file
    Namespace: string option
    // The modules to open at the head of the file
    RequiredOpens: string list
    // Our definitions for feliz style
    Interfaces: InterfaceType list
}

Interfaces are created by using the makeType utility in combination with the type name and a list of attribute definitions

let interfaces: InterfaceType list = [
    makeType "ParamOptions" [
        // attributes go here
    ]
]

Attributes are easily made using the =>> for properties with only one accepted type, and ==> to pass a list of accepted types

makeType "ParamOptions" [
    "testAttribute" =>> nameof float //same as "float"
    "testListAttr" ==> [
        nameof float
        nameof int
        nameof string
    ]
]

The real help here is the definition of enums using feliz style. Simply add a sublist of the string enum options

makeType "ParamOptions" [
                    // enums
    "testEnum" ==> [[ "center"; "right" ]]
    "testMix" ==> [
        // Special constant that is equivalent to
        // yield! [ nameof float; nameof int ]
        number
        // Special constant that is equivalent to
        // yield! [ "float array"; "int array" ]
        numberArray
        [ // enums
            "center"
            "right"
            // you can even do numbers
            // note: above string would need to also be boxed
            box 5
            box 3.2
            box true
        ]
    ]
]

Or maybe you want to define an attribute which builds another object from a list:

makeType "ParamOptions" [
    "label" ==> [
        "string list"
        nameof string
        object "ParamOptions"
    ]
]

Now you can build the schema (use Schema.buildToFile to directly write to a file).

{
    Interfaces = [
        makeType "SomeType" [
            "attr" ==> [
                nameof float
                nameof int
                [ // sublist = 'enums'
                    "x"
                    "y"
                ]
            ]
            "otherAttr" ==> [
                nameof string
            ]
        ]
    ]
} |> Schema.build

type ISomeTypeProp =
    interface end

[<Erase>]
module SomeType =
    [<Erase>]
    type attr =
        static member inline ofFloat(value: float) : ISomeTypeProp = unbox( "attr", value)
        static member inline ofInt(value: int) : ISomeTypeProp = unbox( "attr", value)
        static member inline x: ISomeTypeProp = unbox("attr", "x")
        static member inline y: ISomeTypeProp = unbox("attr", "y")

[<Erase>]
type SomeType =
    static member inline otherAttr(value: string) : ISomeTypeProp = unbox("otherAttr", value)

Non-Goals

We aren't intending to do EVERYTHING using the generator, just the attributes and annoying tedious template work.

We do want to support things like documenting props and adding the ability to alter how type names are handled/generated.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.7.0 157 10/3/2025
0.6.0 155 10/2/2025
0.5.0 154 10/2/2025
0.4.0 156 10/2/2025
0.3.0 165 10/2/2025
0.2.2 159 10/2/2025
0.2.1 170 10/2/2025
0.2.0 148 10/2/2025
0.1.1 141 10/2/2025
0.1.0 170 10/2/2025