AterraEngine.Unions 0.3.0-alpha

Prefix Reserved
Suggested Alternatives

CodeOfChaos.Unions

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

🔗 AterraEngine.Unions 🔗

A Union Library for DotNet

Overview

AterraEngine.Unions is a comprehensive library for creating and managing union types in .NET. It leverages the latest features of C# 13.0 and .NET 9.0 to provide a robust and efficient framework for representing multiple and diverse data types as a single unit. The package was inspired by the OneOf package.

Features

  • Type Safety: Ensure type safety with union types that encapsulate various data forms.
  • Ease of Use: Simplified API to integrate union types seamlessly into your project.
  • Performance Optimizations: Designed with performance in mind to handle high-scale applications.
  • Generate: Not satisfied with the basic unions we have made for you? No worries, you can generate your own using AterraEngine.Unions.Generator
  • Auto Alias: Instead of having a pre-made Union<T0,T1,...> base type which simply provides a IsT0 or AsT1 api, this package generates all unions from the ground up.
    • This allows us to create insert any names we want. By default, it will choose the name of the types chosen for the aliases, example : IsTrue AsString.
    • You can also set your own alias for specific types using the attribute [UnionAliases(aliasT2:"Something")]. See usage in the example below.
  • Up to 16: By default the IUnion<> interface allows up to 16 types within the union. Because we use casting instead of the index based approach by OneOf, there doesn't need to be a limit to this in the future.

Getting Started

Installation

You can install AterraEngine.Unions via NuGet Package Manager:

dotnet add package AterraEngine.Unions

You can install AterraEngine.Unions.Generator via NuGet Package Manager:

dotnet add package AterraEngine.Unions.Generator
Usage

Here is a basic example to demonstrate how to create and use union types with AterraEngine.Unions.

using AterraEngine.Unions;

TrueOrFalse trueOrFalse = new True();

if (trueOrFalse.IsTrue) {    
    // Do stuff here
}
using AterraEngine.Unions;

ManyOneNoneOrError<int, string> union = new Many<int>([1, 2, 3]);
if (union.TryGetAsMany(out Many<T> values) {
  // Do stuff here
}
if (union.TryGetAsOne(out One<T> value) {
  // Do stuff here
}
if (union.TryGetAsNone(out None value) {
  // Do stuff here
}
if (union.TryGetAsError(out Error<T> value) {
  // Do stuff here
}
using AterraEngine.Unions;

ManyOneNoneOrError<int, string> union = new One<int>(1);
switch (union.Value) {
    case Many<int>: //...
    case One<int>: //...
    case None: //...
    case Error: //...
}

Creating your own unions is easily done by installing AterraEngine.Unions.Generators and following the example:

using AterraEngine.Unions;

[UnionAliases(aliasT2:"ErrorTuple")]
public readonly partial struct TrueFalseOrErrorTuple() : IUnion<True, False, (Error<string>, Type)>;
// Which will generate the following, instead of a default generated name for the 3rd type in the union.
// - IsErrorTuple
// - AsErrorTuple
// - TryGetErrorTuple(...)

Here is an advanced example demonstrating a custom union type with user-defined aliases:

using AterraEngine.Unions;

[UnionAliases(aliasT2: "ErrorTuple")]
public readonly partial struct TrueFalseOrErrorTuple : IUnion<True, False, (Error<string>, Type)>;

class Program {
    static void Main() {
        TrueFalseOrErrorTuple union = new True();
        
        if (union.IsTrue) {
            Console.WriteLine("It's true!");
        }

        // Using the custom alias
        union = new ((new Error<string>("An error occurred"), typeof(int)));

        if (union.IsErrorTuple) {
            var errorTuple = union.AsErrorTuple;
            Console.WriteLine($"Error: {errorTuple.Item1.Message}, Type: {errorTuple.Item2}");
        }
    }
}
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.
  • net9.0

    • No dependencies.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on AterraEngine.Unions:

Package Downloads
InfiniLore.Credentials.Auth0.Contracts

A library to handle Auth0 more Easily for the InfiniLore server

InfiniLore.Credentials.Auth0

A library to handle Auth0 more Easily for the InfiniLore server

InfiniLore.Server.Types

A small library of commonly used types within the InfiniLore Server

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
6.1.0 419 9/25/2025 6.1.0 is deprecated because it is no longer maintained.
6.0.1 309 7/28/2025 6.0.1 is deprecated because it is no longer maintained.
6.0.0 287 7/27/2025 6.0.0 is deprecated because it is no longer maintained.
5.3.1 300 6/6/2025 5.3.1 is deprecated because it is no longer maintained.
5.3.0 345 6/4/2025 5.3.0 is deprecated because it is no longer maintained.
5.2.0 312 6/4/2025 5.2.0 is deprecated because it is no longer maintained.
5.1.0 297 6/4/2025 5.1.0 is deprecated because it is no longer maintained.
5.0.0 307 5/30/2025 5.0.0 is deprecated because it is no longer maintained.
4.2.0 345 5/19/2025 4.2.0 is deprecated because it is no longer maintained.
4.1.0 700 3/24/2025 4.1.0 is deprecated because it is no longer maintained.
4.0.1 582 3/15/2025 4.0.1 is deprecated because it is no longer maintained.
4.0.0 295 3/14/2025 4.0.0 is deprecated because it is no longer maintained.
3.12.0 430 3/5/2025 3.12.0 is deprecated because it is no longer maintained.
3.11.0 781 2/15/2025 3.11.0 is deprecated because it is no longer maintained.
3.10.0 294 2/14/2025 3.10.0 is deprecated because it is no longer maintained.
3.9.0 448 2/13/2025 3.9.0 is deprecated because it is no longer maintained.
3.8.0 434 1/29/2025 3.8.0 is deprecated because it is no longer maintained.
3.7.1 288 1/29/2025 3.7.1 is deprecated because it is no longer maintained.
3.6.0 359 1/9/2025 3.6.0 is deprecated because it is no longer maintained.
3.6.0-preview.3 200 1/9/2025 3.6.0-preview.3 is deprecated because it is no longer maintained.
3.6.0-preview.2 202 1/9/2025 3.6.0-preview.2 is deprecated because it is no longer maintained.
3.6.0-preview.1 219 1/9/2025 3.6.0-preview.1 is deprecated because it is no longer maintained.
3.5.0 305 1/7/2025 3.5.0 is deprecated because it is no longer maintained.
3.5.0-preview.1 222 1/9/2025 3.5.0-preview.1 is deprecated because it is no longer maintained.
3.4.0 276 1/7/2025 3.4.0 is deprecated because it is no longer maintained.
3.3.1 271 1/7/2025 3.3.1 is deprecated because it is no longer maintained.
3.3.0 286 1/7/2025 3.3.0 is deprecated because it is no longer maintained.
3.2.1 298 1/6/2025 3.2.1 is deprecated because it is no longer maintained.
3.2.0 288 1/6/2025 3.2.0 is deprecated because it is no longer maintained.
3.0.0 314 1/4/2025 3.0.0 is deprecated because it is no longer maintained.
2.7.1 427 1/1/2025 2.7.1 is deprecated because it is no longer maintained.
2.7.0 354 12/31/2024 2.7.0 is deprecated because it is no longer maintained.
2.6.0 286 12/31/2024 2.6.0 is deprecated because it is no longer maintained.
2.5.0 626 12/10/2024 2.5.0 is deprecated because it is no longer maintained.
2.4.0 292 12/9/2024 2.4.0 is deprecated because it is no longer maintained.
2.3.3 348 12/6/2024 2.3.3 is deprecated because it is no longer maintained.
2.2.0 298 12/6/2024 2.2.0 is deprecated because it is no longer maintained.
2.1.0 305 11/27/2024 2.1.0 is deprecated because it is no longer maintained.
2.0.0 310 11/27/2024 2.0.0 is deprecated because it is no longer maintained.
1.2.0 294 11/21/2024 1.2.0 is deprecated because it is no longer maintained.
1.1.0 284 11/21/2024 1.1.0 is deprecated because it is no longer maintained.
1.0.1 294 11/21/2024 1.0.1 is deprecated because it is no longer maintained.
1.0.0 291 11/19/2024 1.0.0 is deprecated because it is no longer maintained.
0.9.0-alpha 280 11/19/2024 0.9.0-alpha is deprecated because it is no longer maintained.
0.8.0-alpha 278 11/18/2024 0.8.0-alpha is deprecated because it is no longer maintained.
0.7.0-alpha 270 11/18/2024 0.7.0-alpha is deprecated because it is no longer maintained.
0.6.0-alpha 264 11/17/2024 0.6.0-alpha is deprecated because it is no longer maintained.
0.5.1-alpha 272 11/16/2024 0.5.1-alpha is deprecated because it is no longer maintained.
0.5.0-alpha 261 11/16/2024 0.5.0-alpha is deprecated because it is no longer maintained.
0.4.0-alpha 271 11/16/2024 0.4.0-alpha is deprecated because it is no longer maintained.
0.3.0-alpha 280 11/13/2024 0.3.0-alpha is deprecated because it is no longer maintained.
0.2.1-alpha 291 11/11/2024 0.2.1-alpha is deprecated because it is no longer maintained.
0.2.0-alpha 282 11/11/2024 0.2.0-alpha is deprecated because it is no longer maintained.
0.1.0-alpha 293 11/11/2024 0.1.0-alpha is deprecated because it is no longer maintained.