FSharp.SourceDjinn.TypeModel 0.3.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package FSharp.SourceDjinn.TypeModel --version 0.3.0
                    
NuGet\Install-Package FSharp.SourceDjinn.TypeModel -Version 0.3.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="FSharp.SourceDjinn.TypeModel" Version="0.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FSharp.SourceDjinn.TypeModel" Version="0.3.0" />
                    
Directory.Packages.props
<PackageReference Include="FSharp.SourceDjinn.TypeModel" />
                    
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 FSharp.SourceDjinn.TypeModel --version 0.3.0
                    
#r "nuget: FSharp.SourceDjinn.TypeModel, 0.3.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 FSharp.SourceDjinn.TypeModel@0.3.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=FSharp.SourceDjinn.TypeModel&version=0.3.0
                    
Install as a Cake Addin
#tool nuget:?package=FSharp.SourceDjinn.TypeModel&version=0.3.0
                    
Install as a Cake Tool

FSharp.SourceDjinn

Serde.FS Serde.FS.SourceGen

A lightweight engine for extracting a simplified, stable type model from F# source code. Djinn is designed for source generators that scan code for custom marker attributes and generate code based on the types that carry them.

Djinn focuses on syntax, not semantics. It parses F# source files and produces a backend‑agnostic model of modules, namespaces, records, unions, fields, and attributes — far simpler to work with than the full FCS AST.


✨ What Djinn provides

  • Fast, dependency‑light F# AST parsing
  • A clean, stable type model for:
    • records
    • discriminated unions
    • modules and namespaces
    • fields and union cases
    • attributes and constructor/named arguments (including typeof<T>)
  • Entry point detection via a custom marker attribute
  • Helpers for generating F# code from conventions
  • Analyzer‑friendly packaging (ships as a Roslyn analyzer)

Djinn does not perform type checking or symbol resolution. It stays purely syntactic so generators can layer their own semantics on top.


📦 Installation

<PackageReference Include="FSharp.SourceDjinn" Version="0.1.4" PrivateAssets="all" />

Djinn is intended for analyzers and source generators, not runtime use.


🧪 Example: scanning for a custom attribute

This example shows the core use case: extracting a simplified type model and finding types marked with your generator’s attribute.

open FSharp.SourceDjinn

let source = """
module App

[<Generate>]
type Person = { Name: string; Age: int }
"""

let types = TypeModel.extract "/test.fs" source

for t in types do
    if t.HasAttribute "Generate" then
        printfn "Found type: %s" t.FullName
        for f in t.Fields do
            printfn "  Field: %s : %s" f.Name f.TypeName

Output:

Found type: App.Person
  Field: Name : string
  Field: Age : int

This is the heart of Djinn: turn F# source into a clean, usable model for your generator.


⚡ Custom EntryPoint attribute

F# has a unique rule: the real [<EntryPoint>] function must appear last in the compilation order. Source generators run before compilation and cannot control file ordering, so they cannot safely generate a real entry point.

To solve this, Djinn provides a lightweight marker attribute:

[<FSharp.SourceDjinn.TypeModel.EntryPoint>]

This attribute is not the real entry point. Instead, it tells your generator:

“This is the function the generator should wrap in the actual [<EntryPoint>] function it emits.”

Djinn’s EntryPointDetector picks up this attribute during extraction so generators can reliably locate the user’s intended entry point.

Generators typically:

  • scan for [<FSharp.SourceDjinn.EntryPoint>]
  • generate a real [<EntryPoint>] function in a separate file
  • call the user’s function from that generated entry point

This keeps user code clean while ensuring the generated entry point appears in the correct place in the compilation order.


🧩 Architecture overview

Djinn is composed of small, focused components:

  • AstParser — parses F# source into a simplified AST
  • TypeModel — extracts types, fields, union cases, attributes, and module paths
  • EntryPointDetector — finds top‑level entry points
  • Emitter — helps generate F# code using conventions

These components are intentionally minimal so higher‑level libraries can layer semantics and code generation on top.


🌱 Ecosystem

Projects built on Djinn:

  • Serde.FS — idiomatic F# serialization
  • Serde.FS.SourceGen — compile‑time serializer generator
  • Serde.FS.Json — System.Text.Json backend

All projects live under the fs‑djinn GitHub organization.


❤️ Acknowledgments

A special hat tip to Dave Thomas and his work on Myriad. Myriad was one of the first projects to show how flexible and expressive F# metaprogramming could be — taking arbitrary inputs (including F# code) and generating idiomatic F# constructs such as records and discriminated unions, all through a plugin‑based code‑generation flow. SourceDjinn follows in that lineage, focusing on attribute‑driven generation while carrying forward the spirit of making compile‑time F# tooling more accessible.


📄 License

MIT


Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  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 (2)

Showing the top 2 NuGet packages that depend on FSharp.SourceDjinn.TypeModel:

Package Downloads
FSharp.SourceDjinn

F# source generation engine

Serde.FS.SourceGen

Source generator for Serde.FS. Produces metadata and serializers for [Serde] types with full recursive strictness validation. Used by all Serde.FS backends.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.4.0 97 3/18/2026
0.3.0 113 3/17/2026
0.2.2 137 3/5/2026
0.2.1 82 3/5/2026
0.2.0 80 3/5/2026
0.1.1 147 3/1/2026
0.1.0 98 3/1/2026