Unio 1.2.1
Requires NuGet 2.12 or higher.
dotnet add package Unio --version 1.2.1
NuGet\Install-Package Unio -Version 1.2.1
<PackageReference Include="Unio" Version="1.2.1" />
<PackageVersion Include="Unio" Version="1.2.1" />
<PackageReference Include="Unio" />
paket add Unio --version 1.2.1
#r "nuget: Unio, 1.2.1"
#:package Unio@1.2.1
#addin nuget:?package=Unio&version=1.2.1
#tool nuget:?package=Unio&version=1.2.1
Unio
High-performance discriminated unions for C#. Designed with strongly typed generic fields, full value equality semantics and allocation-free pattern matching for maximum performance and type safety.
Usage
Targets .NET 9, .NET 10 and .NET 11 RC1. The core is compatible with Native AOT and trimming, including UnioBase<...> and source-generated named unions. It uses no runtime code generation or reflection.
The package enables IsAotCompatible and verifies reference AOT metadata on .NET 10 and newer. See the Native AOT examples and validation for publish commands.
Union storage and typed matching do not allocate. Accessing Value boxes value types; named union classes, capturing delegates and some formatting paths can allocate.
using Unio;
// Implicit conversion
Unio<int, string> result = 42;
Unio<int, string> error = "not found";
// Exhaustive matching
string text = result.Match(
i => $"Number: {i}",
s => $"Text: {s}");
// Allocation-free matching - pass state instead of capturing variables
// (no closure object allocated per call)
string prefix = "Result";
string text2 = result.Match(prefix,
static (p, i) => $"{p}: {i}",
static (p, s) => $"{p}: {s}");
// Allocation-free side-effect switch
result.Switch((prefix, Console.Out),
static (s, i) => s.Out.WriteLine($"{s.prefix}: {i}"),
static (s, str) => s.Out.WriteLine($"{s.prefix}: {str}"));
// Safe TryGet pattern
if (result.TryGetT0(out int number))
Console.WriteLine(number);
| Product | Versions 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 is compatible. 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. net11.0 is compatible. |
-
net10.0
- No dependencies.
-
net11.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages (4)
Showing the top 4 NuGet packages that depend on Unio:
| Package | Downloads |
|---|---|
|
Tlib.Union
Package Description |
|
|
Steelax.Pufflow.Operators
Operators (Buffer, Chunk, Timeout, Warm, ...) for Steelax.Pufflow dataflow pipelines. |
|
|
Unio.Extensions
Unio provides high-performance, struct-based discriminated unions for C#. Zero-allocation, exhaustive matching, Match, Switch and TryGet patterns and full value semantics. Simple, performant and scalable. |
|
|
Unio.AspNetCore
Unio provides high-performance, struct-based discriminated unions for C#. Zero-allocation, exhaustive matching, Match, Switch and TryGet patterns and full value semantics. Simple, performant and scalable. |
GitHub repositories
This package is not used by any popular GitHub repositories.