Stateflows.Extensions.UnionTypes 0.23.1-beta

Prefix Reserved
This is a prerelease version of Stateflows.Extensions.UnionTypes.
dotnet add package Stateflows.Extensions.UnionTypes --version 0.23.1-beta
                    
NuGet\Install-Package Stateflows.Extensions.UnionTypes -Version 0.23.1-beta
                    
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="Stateflows.Extensions.UnionTypes" Version="0.23.1-beta" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Stateflows.Extensions.UnionTypes" Version="0.23.1-beta" />
                    
Directory.Packages.props
<PackageReference Include="Stateflows.Extensions.UnionTypes" />
                    
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 Stateflows.Extensions.UnionTypes --version 0.23.1-beta
                    
#r "nuget: Stateflows.Extensions.UnionTypes, 0.23.1-beta"
                    
#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 Stateflows.Extensions.UnionTypes@0.23.1-beta
                    
#: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=Stateflows.Extensions.UnionTypes&version=0.23.1-beta&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Stateflows.Extensions.UnionTypes&version=0.23.1-beta&prerelease
                    
Install as a Cake Tool

C# union type mapping

Stateflows.Extensions.UnionTypes targets .NET 11 and maps C# union trigger declarations to their case types, like the OneOf extension does for OneOf types. Register it before defining behaviors:

using Stateflows;

public sealed record Approved;
public sealed record Rejected;
public union Decision(Approved, Rejected);

// Inside the host's service configuration:
services.AddStateflows(stateflows => stateflows
    .AddUnionTypes()
    .AddStateMachines(machines => machines
        .AddStateMachine("review", machine => machine
            .AddInitialState("pending", state => state
                .AddTransition<Decision>("decided"))
            .AddState("decided"))));

Send an Approved or Rejected event to enable the transition. Mapping expands the trigger declaration; it does not unwrap union instances sent as payloads, construct union values, or change event serialization. Existing projects can continue targeting .NET 10; only applications referencing this extension need .NET 11.

The mapper recognizes System.Runtime.CompilerServices.UnionAttribute, including compiler-generated union declarations and manually implemented union patterns. Cases come from public single-parameter constructors, or from public static Create methods returning the union on its nested IUnionMembers provider (including inherited provider members). Closed generic unions and in creation parameters are supported. Nullable value-type cases remain Nullable<T>; nested union cases are not recursively flattened, matching the existing type-mapper pipeline.

Implementation follows the C# union specification. An invalid attributed union without eligible creation members raises an error during mapping rather than silently registering an unrelated trigger.

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
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.23.1-beta 38 11/12/2026
0.23.0-beta 47 11/11/2026