Emik.SourceGenerators.Choices 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Emik.SourceGenerators.Choices --version 1.0.1                
NuGet\Install-Package Emik.SourceGenerators.Choices -Version 1.0.1                
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="Emik.SourceGenerators.Choices" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Emik.SourceGenerators.Choices --version 1.0.1                
#r "nuget: Emik.SourceGenerators.Choices, 1.0.1"                
#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.
// Install Emik.SourceGenerators.Choices as a Cake Addin
#addin nuget:?package=Emik.SourceGenerators.Choices&version=1.0.1

// Install Emik.SourceGenerators.Choices as a Cake Tool
#tool nuget:?package=Emik.SourceGenerators.Choices&version=1.0.1                

Emik.Analyzers.Choices

NuGet package License

Annotate [Choice] to transform your type into a highly performant and flexible disjoint union.

Massive thanks to hikarin522's ValueVariant for being the inspiration to this source generator.

This project has a dependency to Emik.Morsels, if you are building this project, refer to its README first.



Examples

// Example 1
[Choice(typeof((int Integer, float Floating, ValueTuple Unknown)), false)]
partial class Number;
// Example 1's Output
partial class Number :
    global::System.IComparable,
    global::System.IComparable<object>,
    global::System.IComparable<global::Emik.SourceGenerators.Choices.Generated.Tests.Number>,
#if NET7_0_OR_GREATER
    global::System.Numerics.IComparisonOperators<global::Emik.SourceGenerators.Choices.Generated.Tests.Number, global::Emik.SourceGenerators.Choices.Generated.Tests.Number, bool>,
#endif
    global::System.IEquatable<object>,
    global::System.IEquatable<global::Emik.SourceGenerators.Choices.Generated.Tests.Number>
{
    /// <summary>
    /// Compact representation of all unmanaged memory within the union <see cref="Emik.SourceGenerators.Choices.Generated.Tests.Number"/>.
    /// </summary>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Runtime.InteropServices.StructLayout(LayoutKind.Explicit)]
    partial struct Unmanaged
    {
        [global::System.Runtime.InteropServices.FieldOffsetAttribute(0)]
        internal int _integer;

        [global::System.Runtime.InteropServices.FieldOffsetAttribute(0)]
        internal float _floating;
    }

    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    private byte _discriminator;

    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    private Unmanaged _unmanaged;

    /// <summary>
    /// Initializes a new instance of the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.Number"/> class with the variant <see cref="Integer"/> of type <see cref="int"/>.
    /// </summary>
    /// <param name="integer">The variant.</param>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public Number(int integer)
    {
        _discriminator = 0;
        _unmanaged._integer = integer;
    }

    /// <summary>
    /// Initializes a new instance of the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.Number"/> class with the variant <see cref="Floating"/> of type <see cref="float"/>.
    /// </summary>
    /// <param name="floating">The variant.</param>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public Number(float floating)
    {
        _discriminator = 1;
        _unmanaged._floating = floating;
    }

    /// <summary>
    /// Initializes a new instance of the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.Number"/> class with the variant Unknown of type <see cref="System.ValueTuple"/>.
    /// </summary>
    /// <param name="unknown">The variant.</param>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public Number(System.ValueTuple unknown = default)
    {
        _discriminator = 2;
    }

    /// <summary>
    /// Gets the value determining if the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.Number"/> is the variant <see cref="Integer"/> of type <see cref="int"/>.
    /// </summary>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    public bool IsInteger
    {
        [global::System.Diagnostics.Contracts.PureAttribute]
        [global::System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, "Integer")]
        [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
        get => _discriminator is 0;
    }

    /// <summary>
    /// Gets the value determining if the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.Number"/> is the variant <see cref="Floating"/> of type <see cref="float"/>.
    /// </summary>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    public bool IsFloating
    {
        [global::System.Diagnostics.Contracts.PureAttribute]
        [global::System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, "Floating")]
        [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
        get => _discriminator is 1;
    }

    /// <summary>
    /// Gets the value determining if the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.Number"/> is the variant Unknown of type <see cref="System.ValueTuple"/>.
    /// </summary>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    public bool IsUnknown
    {
        [global::System.Diagnostics.Contracts.PureAttribute]
        [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
        get => _discriminator is 2;
    }

    /// <summary>
    /// Gets the <see cref="int"/> variant.
    /// </summary>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    public int Integer
    {
        [global::System.Diagnostics.Contracts.PureAttribute]
        [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
        get => _discriminator is 0 ? _unmanaged._integer : default;
        [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
        private set
        {
            _discriminator = 0;
            _unmanaged._integer = value;
        }
    }

    /// <summary>
    /// Gets the <see cref="float"/> variant.
    /// </summary>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    public float Floating
    {
        [global::System.Diagnostics.Contracts.PureAttribute]
        [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
        get => _discriminator is 1 ? _unmanaged._floating : default;
        [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
        private set
        {
            _discriminator = 1;
            _unmanaged._floating = value;
        }
    }

    /// <summary>
    /// Implicitly converts the <see cref="int"/> parameter to the union.
    /// </summary>
    /// <param name="integer">The parameter to pass onto the constructor.</param>
    /// <returns>The union containing the parameter <paramref name="integer"/>.</returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public static implicit operator global::Emik.SourceGenerators.Choices.Generated.Tests.Number(int integer)
        => new global::Emik.SourceGenerators.Choices.Generated.Tests.Number(integer);

    /// <summary>
    /// Explicitly converts the union to the target type <see cref="int"/>.
    /// </summary>
    /// <param name="x">The union to access its property.</param>
    /// <returns>The getter of the union <paramref name="x"/>.</returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public static explicit operator int(global::Emik.SourceGenerators.Choices.Generated.Tests.Number x)
        => x.Integer;

    /// <summary>
    /// Implicitly converts the <see cref="float"/> parameter to the union.
    /// </summary>
    /// <param name="floating">The parameter to pass onto the constructor.</param>
    /// <returns>The union containing the parameter <paramref name="floating"/>.</returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public static implicit operator global::Emik.SourceGenerators.Choices.Generated.Tests.Number(float floating)
        => new global::Emik.SourceGenerators.Choices.Generated.Tests.Number(floating);

    /// <summary>
    /// Explicitly converts the union to the target type <see cref="float"/>.
    /// </summary>
    /// <param name="x">The union to access its property.</param>
    /// <returns>The getter of the union <paramref name="x"/>.</returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public static explicit operator float(global::Emik.SourceGenerators.Choices.Generated.Tests.Number x)
        => x.Floating;

    /// <summary>
    /// Implicitly converts the <see cref="System.ValueTuple"/> parameter to the union.
    /// </summary>
    /// <param name="unknown">The parameter to pass onto the constructor.</param>
    /// <returns>The union containing the parameter <paramref name="unknown"/>.</returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public static implicit operator global::Emik.SourceGenerators.Choices.Generated.Tests.Number(System.ValueTuple unknown)
        => new global::Emik.SourceGenerators.Choices.Generated.Tests.Number(unknown);

    /// <summary>
    /// Creates a new instance of the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.Number"/> class with the variant <see cref="Integer"/> of type <see cref="int"/>.
    /// </summary>
    /// <param name="integer">The value to pass into the type.</param>
    /// <returns>The union containing the parameter <paramref name="integer"/>.</returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public static global::Emik.SourceGenerators.Choices.Generated.Tests.Number OfInteger(int integer)
        => new global::Emik.SourceGenerators.Choices.Generated.Tests.Number(integer);

    /// <summary>
    /// Creates a new instance of the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.Number"/> class with the variant <see cref="Floating"/> of type <see cref="float"/>.
    /// </summary>
    /// <param name="floating">The value to pass into the type.</param>
    /// <returns>The union containing the parameter <paramref name="floating"/>.</returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public static global::Emik.SourceGenerators.Choices.Generated.Tests.Number OfFloating(float floating)
        => new global::Emik.SourceGenerators.Choices.Generated.Tests.Number(floating);

    /// <summary>
    /// Creates a new instance of the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.Number"/> class with the variant Unknown of type <see cref="System.ValueTuple"/>.
    /// </summary>
    /// <param name="unknown">The value to pass into the type.</param>
    /// <returns>The union containing the parameter <paramref name="unknown"/>.</returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public static global::Emik.SourceGenerators.Choices.Generated.Tests.Number OfUnknown(System.ValueTuple unknown = default)
        => new global::Emik.SourceGenerators.Choices.Generated.Tests.Number(unknown);

    /// <summary>
    /// Determines whether the left-hand side is equal to the right.
    /// </summary>
    /// <param name="left">The left-hand side.</param>
    /// <param name="right">The right-hand side.</param>
    /// <returns>
    /// The value determining whether the parameter <paramref name="left"/>
    /// is equal to the parameter <paramref name="right"/>.
    /// </returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public static bool operator ==(Emik.SourceGenerators.Choices.Generated.Tests.Number? left, Emik.SourceGenerators.Choices.Generated.Tests.Number? right)
        => left is null ? right is null : right is not null && (left._discriminator == right._discriminator) && (left._discriminator
        switch
        {
            0 => left.Integer == right.Integer,
            1 => left.Floating == right.Floating,
            2 => true,
            _ => throw new global::System.InvalidOperationException(),
        });
    
    /// <summary>
    /// Determines whether the left-hand side is unequal to the right.
    /// </summary>
    /// <param name="left">The left-hand side.</param>
    /// <param name="right">The right-hand side.</param>
    /// <returns>
    /// The value determining whether the parameter <paramref name="left"/>
    /// is unequal to the parameter <paramref name="right"/>.
    /// </returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public static bool operator !=(Emik.SourceGenerators.Choices.Generated.Tests.Number? left, Emik.SourceGenerators.Choices.Generated.Tests.Number? right)
        => !(left == right);

    /// <summary>
    /// Determines whether the left-hand side is greater than the right.
    /// </summary>
    /// <param name="left">The left-hand side.</param>
    /// <param name="right">The right-hand side.</param>
    /// <returns>
    /// The value determining whether the parameter <paramref name="left"/>
    /// is greater than the parameter <paramref name="right"/>.
    /// </returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public static bool operator >(Emik.SourceGenerators.Choices.Generated.Tests.Number? left, Emik.SourceGenerators.Choices.Generated.Tests.Number? right)
        => left is null ? right is null : right is not null && (left._discriminator == right._discriminator) && (left._discriminator
        switch
        {
            0 => left.Integer > right.Integer,
            1 => left.Floating > right.Floating,
            2 => true,
            _ => throw new global::System.InvalidOperationException(),
        });

    /// <summary>
    /// Determines whether the left-hand side is greater than or equal to the right.
    /// </summary>
    /// <param name="left">The left-hand side.</param>
    /// <param name="right">The right-hand side.</param>
    /// <returns>
    /// The value determining whether the parameter <paramref name="left"/>
    /// is greater than or equal to the parameter <paramref name="right"/>.
    /// </returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public static bool operator >=(Emik.SourceGenerators.Choices.Generated.Tests.Number? left, Emik.SourceGenerators.Choices.Generated.Tests.Number? right)
        => left == right || left > right;

    /// <summary>
    /// Determines whether the left-hand side is less than the right.
    /// </summary>
    /// <param name="left">The left-hand side.</param>
    /// <param name="right">The right-hand side.</param>
    /// <returns>
    /// The value determining whether the parameter <paramref name="left"/>
    /// is less than the parameter <paramref name="right"/>.
    /// </returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public static bool operator <(Emik.SourceGenerators.Choices.Generated.Tests.Number? left, Emik.SourceGenerators.Choices.Generated.Tests.Number? right)
        => right > left;

    /// <summary>
    /// Determines whether the left-hand side is less than or equal to the right.
    /// </summary>
    /// <param name="left">The left-hand side.</param>
    /// <param name="right">The right-hand side.</param>
    /// <returns>
    /// The value determining whether the parameter <paramref name="left"/>
    /// is less than or equal to the parameter <paramref name="right"/>.
    /// </returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public static bool operator <=(Emik.SourceGenerators.Choices.Generated.Tests.Number? left, Emik.SourceGenerators.Choices.Generated.Tests.Number? right)
        => right >= left;

    /// <inheritdoc cref="object.Equals(object)"/>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public override bool Equals(object? obj)
        => obj is global::Emik.SourceGenerators.Choices.Generated.Tests.Number x && Equals(x);

    /// <inheritdoc />
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public bool Equals(Emik.SourceGenerators.Choices.Generated.Tests.Number? other)
        => this == other;

    /// <inheritdoc cref="IComparable.CompareTo(object)"/>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public int CompareTo(object? obj)
        => obj is null ? 1 : obj is global::Emik.SourceGenerators.Choices.Generated.Tests.Number x ? CompareTo(x) : -1;

    /// <inheritdoc />
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public int CompareTo(Emik.SourceGenerators.Choices.Generated.Tests.Number? other)
        => other is null ? 1 : Equals(other) ? 0 : -1;

    /// <inheritdoc />
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public override int GetHashCode()
        => unchecked(_discriminator * 578537) ^
        (_discriminator switch
        {
            0 => Integer.GetHashCode(),
            1 => Floating.GetHashCode(),
            2 => 0,
            _ => throw new global::System.InvalidOperationException(),
        });

    /// <inheritdoc />
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public override string ToString()
        => _discriminator switch
        {
            0 => $"{nameof(Integer)}({Integer})",
            1 => $"{nameof(Floating)}({Floating})",
            2 => "Unknown",
            _ => throw new global::System.InvalidOperationException(),
        };

    /// <summary>
    /// Invokes the callback based on current variance.
    /// </summary>
    /// <param name="onInteger">The callback to use when the contract of the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.Number"/> class with the variant <see cref="Integer"/> of type <see cref="int"/> is held.</param>
    /// <param name="onFloating">The callback to use when the contract of the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.Number"/> class with the variant <see cref="Floating"/> of type <see cref="float"/> is held.</param>
    /// <param name="onUnknown">The callback to use when the contract of the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.Number"/> class with the variant Unknown of type <see cref="System.ValueTuple"/> is held.</param>
    /// <returns>Itself.</returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public Emik.SourceGenerators.Choices.Generated.Tests.Number? Map(
        global::System.Action<int>? onInteger = null,
        global::System.Action<float>? onFloating = null,
        global::System.Action? onUnknown = null
    )
    {
        switch (_discriminator)
        {
            case 0:
                onInteger?.Invoke(Integer);
                return this;
            case 1:
                onFloating?.Invoke(Floating);
                return this;
            case 2:
                onUnknown?.Invoke();
                return this;
            default: throw new global::System.InvalidOperationException();
        }
    }

    /// <summary>
    /// Maps each variant to <typeparamref name="TMappingResult"/>.
    /// </summary>
    /// <typeparam name="TMappingResult">The resulting type from the mapping.</typeparam>
    /// <param name="onInteger">The callback to use when the contract of the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.Number"/> class with the variant <see cref="Integer"/> of type <see cref="int"/> is held.</param>
    /// <param name="onFloating">The callback to use when the contract of the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.Number"/> class with the variant <see cref="Floating"/> of type <see cref="float"/> is held.</param>
    /// <param name="onUnknown">The callback to use when the contract of the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.Number"/> class with the variant Unknown of type <see cref="System.ValueTuple"/> is held.</param>
    /// <returns>
    /// The resulting value from one of the parameters based on the current state of the object.
    /// </returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public TMappingResult Map<TMappingResult>(
        global::System.Func<int, TMappingResult> onInteger,
        global::System.Func<float, TMappingResult> onFloating,
        global::System.Func<TMappingResult> onUnknown
    )
        => _discriminator
        switch
        {
            0 => onInteger(Integer),
            1 => onFloating(Floating),
            2 => onUnknown(),
            _ => throw new global::System.InvalidOperationException(),
        };
}
// Example 2
[Choice]
readonly partial record struct Result<TOk, TErr>
{
    readonly TOk? _ok;

    readonly TErr? _err;
}
// Example 2's Output
[global::System.Runtime.InteropServices.StructLayoutAttribute(global::System.Runtime.InteropServices.LayoutKind.Auto)]
partial record struct Result<TOk, TErr> :
    global::System.IComparable,
    global::System.IComparable<object>,
    global::System.IComparable<global::Emik.SourceGenerators.Choices.Generated.Tests.Result<TOk, TErr>>,
#if NET7_0_OR_GREATER
    global::System.Numerics.IComparisonOperators<global::Emik.SourceGenerators.Choices.Generated.Tests.Result<TOk, TErr>, global::Emik.SourceGenerators.Choices.Generated.Tests.Result<TOk, TErr>, bool>,
#endif
    global::System.IEquatable<object>,
    global::System.IEquatable<global::Emik.SourceGenerators.Choices.Generated.Tests.Result<TOk, TErr>>
{
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    private readonly byte _discriminator;

    /// <summary>
    /// Initializes a new instance of the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.Result{TOk, TErr}"/> record struct with the variant <see cref="Ok"/> of type <typeparamref name="TOk"/>.
    /// </summary>
    /// <param name="ok">The variant.</param>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public Result(TOk? ok)
    {
        _discriminator = 0;
        _ok = ok;
    }

    /// <summary>
    /// Initializes a new instance of the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.Result{TOk, TErr}"/> record struct with the variant <see cref="Err"/> of type <typeparamref name="TErr"/>.
    /// </summary>
    /// <param name="err">The variant.</param>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public Result(TErr? err)
    {
        _discriminator = 1;
        _err = err;
    }

    /// <summary>
    /// Gets the value determining if the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.Result{TOk, TErr}"/> is the variant <see cref="Ok"/> of type <typeparamref name="TOk"/>.
    /// </summary>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    public readonly bool IsOk
    {
        [global::System.Diagnostics.Contracts.PureAttribute]
        [global::System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, "Ok")]
        [global::System.Diagnostics.CodeAnalysis.MemberNotNullWhen(false, "Err")]
        [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
        get => _discriminator is 0;
    }

    /// <summary>
    /// Gets the value determining if the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.Result{TOk, TErr}"/> is the variant <see cref="Err"/> of type <typeparamref name="TErr"/>.
    /// </summary>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    public readonly bool IsErr
    {
        [global::System.Diagnostics.Contracts.PureAttribute]
        [global::System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, "Err")]
        [global::System.Diagnostics.CodeAnalysis.MemberNotNullWhen(false, "Ok")]
        [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
        get => _discriminator is 1;
    }

    /// <summary>
    /// Gets the <typeparamref name="TOk"/> variant.
    /// </summary>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    public readonly TOk? Ok
    {
        [global::System.Diagnostics.Contracts.PureAttribute]
        [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
        get => _discriminator is 0 ? _ok : default;
    }

    /// <summary>
    /// Gets the <typeparamref name="TErr"/> variant.
    /// </summary>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    public readonly TErr? Err
    {
        [global::System.Diagnostics.Contracts.PureAttribute]
        [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
        get => _discriminator is 1 ? _err : default;
    }

    /// <summary>
    /// Creates a new instance of the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.Result{TOk, TErr}"/> record struct with the variant <see cref="Ok"/> of type <typeparamref name="TOk"/>.
    /// </summary>
    /// <param name="ok">The value to pass into the type.</param>
    /// <returns>The union containing the parameter <paramref name="ok"/>.</returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public static global::Emik.SourceGenerators.Choices.Generated.Tests.Result<TOk, TErr> OfOk(TOk? ok)
        => new global::Emik.SourceGenerators.Choices.Generated.Tests.Result<TOk, TErr>(ok);

    /// <summary>
    /// Creates a new instance of the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.Result{TOk, TErr}"/> record struct with the variant <see cref="Err"/> of type <typeparamref name="TErr"/>.
    /// </summary>
    /// <param name="err">The value to pass into the type.</param>
    /// <returns>The union containing the parameter <paramref name="err"/>.</returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public static global::Emik.SourceGenerators.Choices.Generated.Tests.Result<TOk, TErr> OfErr(TErr? err)
        => new global::Emik.SourceGenerators.Choices.Generated.Tests.Result<TOk, TErr>(err);

    /// <summary>
    /// Determines whether the left-hand side is greater than the right.
    /// </summary>
    /// <param name="left">The left-hand side.</param>
    /// <param name="right">The right-hand side.</param>
    /// <returns>
    /// The value determining whether the parameter <paramref name="left"/>
    /// is greater than the parameter <paramref name="right"/>.
    /// </returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public static bool operator >(Emik.SourceGenerators.Choices.Generated.Tests.Result<TOk, TErr> left, Emik.SourceGenerators.Choices.Generated.Tests.Result<TOk, TErr> right)
        => (left._discriminator == right._discriminator) && (left._discriminator
        switch
        {
            0 => false,
            1 => false,
            _ => throw new global::System.InvalidOperationException(),
        });

    /// <summary>
    /// Determines whether the left-hand side is greater than or equal to the right.
    /// </summary>
    /// <param name="left">The left-hand side.</param>
    /// <param name="right">The right-hand side.</param>
    /// <returns>
    /// The value determining whether the parameter <paramref name="left"/>
    /// is greater than or equal to the parameter <paramref name="right"/>.
    /// </returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public static bool operator >=(Emik.SourceGenerators.Choices.Generated.Tests.Result<TOk, TErr> left, Emik.SourceGenerators.Choices.Generated.Tests.Result<TOk, TErr> right)
        => left == right || left > right;

    /// <summary>
    /// Determines whether the left-hand side is less than the right.
    /// </summary>
    /// <param name="left">The left-hand side.</param>
    /// <param name="right">The right-hand side.</param>
    /// <returns>
    /// The value determining whether the parameter <paramref name="left"/>
    /// is less than the parameter <paramref name="right"/>.
    /// </returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public static bool operator <(Emik.SourceGenerators.Choices.Generated.Tests.Result<TOk, TErr> left, Emik.SourceGenerators.Choices.Generated.Tests.Result<TOk, TErr> right)
        => right > left;

    /// <summary>
    /// Determines whether the left-hand side is less than or equal to the right.
    /// </summary>
    /// <param name="left">The left-hand side.</param>
    /// <param name="right">The right-hand side.</param>
    /// <returns>
    /// The value determining whether the parameter <paramref name="left"/>
    /// is less than or equal to the parameter <paramref name="right"/>.
    /// </returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public static bool operator <=(Emik.SourceGenerators.Choices.Generated.Tests.Result<TOk, TErr> left, Emik.SourceGenerators.Choices.Generated.Tests.Result<TOk, TErr> right)
        => right >= left;

    /// <inheritdoc />
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public readonly bool Equals(Emik.SourceGenerators.Choices.Generated.Tests.Result<TOk, TErr> other)
        => this == other;

    /// <inheritdoc cref="IComparable.CompareTo(object)"/>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public readonly int CompareTo(object? obj)
        => obj is null ? 1 : obj is global::Emik.SourceGenerators.Choices.Generated.Tests.Result<TOk, TErr> x ? CompareTo(x) : -1;

    /// <inheritdoc />
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public readonly int CompareTo(Emik.SourceGenerators.Choices.Generated.Tests.Result<TOk, TErr> other)
        => Equals(other) ? 0 : -1;

    /// <inheritdoc />
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public readonly override int GetHashCode()
        => unchecked(_discriminator * 673447) ^
        (_discriminator switch
        {
            0 => Ok!.GetHashCode(),
            1 => Err!.GetHashCode(),
            _ => throw new global::System.InvalidOperationException(),
        });

    /// <inheritdoc />
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public readonly override string ToString()
        => _discriminator switch
        {
            0 => $"{nameof(Ok)}({Ok})",
            1 => $"{nameof(Err)}({Err})",
            _ => throw new global::System.InvalidOperationException(),
        };

    /// <summary>
    /// Invokes the callback based on current variance.
    /// </summary>
    /// <param name="onOk">The callback to use when the contract of the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.Result{TOk, TErr}"/> record struct with the variant <see cref="Ok"/> of type <typeparamref name="TOk"/> is held.</param>
    /// <param name="onErr">The callback to use when the contract of the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.Result{TOk, TErr}"/> record struct with the variant <see cref="Err"/> of type <typeparamref name="TErr"/> is held.</param>
    /// <returns>Itself.</returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public readonly Emik.SourceGenerators.Choices.Generated.Tests.Result<TOk, TErr> Map(
        global::System.Action<TOk?>? onOk = null,
        global::System.Action<TErr?>? onErr = null
    )
    {
        switch (_discriminator)
        {
            case 0:
                onOk?.Invoke(Ok!);
                return this;
            case 1:
                onErr?.Invoke(Err!);
                return this;
            default: throw new global::System.InvalidOperationException();
        }
    }

    /// <summary>
    /// Maps each variant to <typeparamref name="TMappingResult"/>.
    /// </summary>
    /// <typeparam name="TMappingResult">The resulting type from the mapping.</typeparam>
    /// <param name="onOk">The callback to use when the contract of the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.Result{TOk, TErr}"/> record struct with the variant <see cref="Ok"/> of type <typeparamref name="TOk"/> is held.</param>
    /// <param name="onErr">The callback to use when the contract of the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.Result{TOk, TErr}"/> record struct with the variant <see cref="Err"/> of type <typeparamref name="TErr"/> is held.</param>
    /// <returns>
    /// The resulting value from one of the parameters based on the current state of the object.
    /// </returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public readonly TMappingResult Map<TMappingResult>(
        global::System.Func<TOk?, TMappingResult> onOk,
        global::System.Func<TErr?, TMappingResult> onErr
    )
        => _discriminator
        switch
        {
            0 => onOk(Ok!),
            1 => onErr(Err!),
            _ => throw new global::System.InvalidOperationException(),
        };
}
// Example 3
[Choice(true), StructLayout(LayoutKind.Sequential)]
ref partial struct SpanEncodings
{
    Span<byte> _utf8;

    Span<char> _utf16;
}
// Example 3's Output
partial struct SpanEncodings
{
    /// <summary>
    /// Explicit side effect delegate for the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings"/> struct with the variant <see cref="Utf8"/> of type <see cref="System.Span{T}"/> due to it being a by-ref like type.
    /// </summary>
    /// <param name="utf8">The referenced value.</param>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    public delegate void Utf8Handler(System.Span<byte> utf8);

    /// <summary>
    /// Explicit mapper delegate for the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings"/> struct with the variant <see cref="Utf8"/> of type <see cref="System.Span{T}"/> due to it being a by-ref like type.
    /// </summary>
    /// <typeparam name="TMappingResult">The type of value to return.</typeparam>
    /// <param name="utf8">The referenced value.</param>
    /// <returns>The result of the mapping.</returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    public delegate TMappingResult Utf8Handler<out TMappingResult>(System.Span<byte> utf8);

    /// <summary>
    /// Explicit side effect delegate for the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings"/> struct with the variant <see cref="Utf16"/> of type <see cref="System.Span{T}"/> due to it being a by-ref like type.
    /// </summary>
    /// <param name="utf16">The referenced value.</param>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    public delegate void Utf16Handler(System.Span<char> utf16);

    /// <summary>
    /// Explicit mapper delegate for the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings"/> struct with the variant <see cref="Utf16"/> of type <see cref="System.Span{T}"/> due to it being a by-ref like type.
    /// </summary>
    /// <typeparam name="TMappingResult">The type of value to return.</typeparam>
    /// <param name="utf16">The referenced value.</param>
    /// <returns>The result of the mapping.</returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    public delegate TMappingResult Utf16Handler<out TMappingResult>(System.Span<char> utf16);

    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    private byte _discriminator;

    /// <summary>
    /// Initializes a new instance of the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings"/> struct with the variant <see cref="Utf8"/> of type <see cref="System.Span{T}"/>.
    /// </summary>
    /// <param name="utf8">The variant.</param>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public SpanEncodings(System.Span<byte> utf8)
    {
        _discriminator = 0;
        _utf8 = utf8;
    }

    /// <summary>
    /// Initializes a new instance of the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings"/> struct with the variant <see cref="Utf16"/> of type <see cref="System.Span{T}"/>.
    /// </summary>
    /// <param name="utf16">The variant.</param>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public SpanEncodings(System.Span<char> utf16)
    {
        _discriminator = 1;
        _utf16 = utf16;
    }

    /// <summary>
    /// Gets the value determining if the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings"/> is the variant <see cref="Utf8"/> of type <see cref="System.Span{T}"/>.
    /// </summary>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    public readonly bool IsUtf8
    {
        [global::System.Diagnostics.Contracts.PureAttribute]
        [global::System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, "Utf8")]
        [global::System.Diagnostics.CodeAnalysis.MemberNotNullWhen(false, "Utf16")]
        [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
        get => _discriminator is 0;
    }

    /// <summary>
    /// Gets the value determining if the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings"/> is the variant <see cref="Utf16"/> of type <see cref="System.Span{T}"/>.
    /// </summary>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    public readonly bool IsUtf16
    {
        [global::System.Diagnostics.Contracts.PureAttribute]
        [global::System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, "Utf16")]
        [global::System.Diagnostics.CodeAnalysis.MemberNotNullWhen(false, "Utf8")]
        [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
        get => _discriminator is 1;
    }

    /// <summary>
    /// Gets or sets the <see cref="System.Span{T}"/> variant.
    /// </summary>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    public System.Span<byte> Utf8
    {
        [global::System.Diagnostics.Contracts.PureAttribute]
        [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
        readonly get => _discriminator is 0 ? _utf8 : default;
        [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
        set
        {
            _discriminator = 0;
            _utf8 = value;
        }
    }

    /// <summary>
    /// Gets or sets the <see cref="System.Span{T}"/> variant.
    /// </summary>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    public System.Span<char> Utf16
    {
        [global::System.Diagnostics.Contracts.PureAttribute]
        [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
        readonly get => _discriminator is 1 ? _utf16 : default;
        [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
        set
        {
            _discriminator = 1;
            _utf16 = value;
        }
    }

    /// <summary>
    /// Implicitly converts the <see cref="System.Span{T}"/> parameter to the union.
    /// </summary>
    /// <param name="utf8">The parameter to pass onto the constructor.</param>
    /// <returns>The union containing the parameter <paramref name="utf8"/>.</returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public static implicit operator global::Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings(System.Span<byte> utf8)
        => new global::Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings(utf8);

    /// <summary>
    /// Explicitly converts the union to the target type <see cref="System.Span{T}"/>.
    /// </summary>
    /// <param name="x">The union to access its property.</param>
    /// <returns>The getter of the union <paramref name="x"/>.</returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public static explicit operator System.Span<byte>(global::Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings x)
        => x.Utf8;

    /// <summary>
    /// Implicitly converts the <see cref="System.Span{T}"/> parameter to the union.
    /// </summary>
    /// <param name="utf16">The parameter to pass onto the constructor.</param>
    /// <returns>The union containing the parameter <paramref name="utf16"/>.</returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public static implicit operator global::Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings(System.Span<char> utf16)
        => new global::Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings(utf16);

    /// <summary>
    /// Explicitly converts the union to the target type <see cref="System.Span{T}"/>.
    /// </summary>
    /// <param name="x">The union to access its property.</param>
    /// <returns>The getter of the union <paramref name="x"/>.</returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public static explicit operator System.Span<char>(global::Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings x)
        => x.Utf16;

    /// <summary>
    /// Creates a new instance of the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings"/> struct with the variant <see cref="Utf8"/> of type <see cref="System.Span{T}"/>.
    /// </summary>
    /// <param name="utf8">The value to pass into the type.</param>
    /// <returns>The union containing the parameter <paramref name="utf8"/>.</returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public static global::Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings OfUtf8(System.Span<byte> utf8)
        => new global::Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings(utf8);

    /// <summary>
    /// Creates a new instance of the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings"/> struct with the variant <see cref="Utf16"/> of type <see cref="System.Span{T}"/>.
    /// </summary>
    /// <param name="utf16">The value to pass into the type.</param>
    /// <returns>The union containing the parameter <paramref name="utf16"/>.</returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public static global::Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings OfUtf16(System.Span<char> utf16)
        => new global::Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings(utf16);

    /// <summary>
    /// Determines whether the left-hand side is equal to the right.
    /// </summary>
    /// <param name="left">The left-hand side.</param>
    /// <param name="right">The right-hand side.</param>
    /// <returns>
    /// The value determining whether the parameter <paramref name="left"/>
    /// is equal to the parameter <paramref name="right"/>.
    /// </returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public static bool operator ==(Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings left, Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings right)
        => (left._discriminator == right._discriminator) && (left._discriminator
        switch
        {
            0 => false,
            1 => false,
            _ => throw new global::System.InvalidOperationException(),
        });
    
    /// <summary>
    /// Determines whether the left-hand side is unequal to the right.
    /// </summary>
    /// <param name="left">The left-hand side.</param>
    /// <param name="right">The right-hand side.</param>
    /// <returns>
    /// The value determining whether the parameter <paramref name="left"/>
    /// is unequal to the parameter <paramref name="right"/>.
    /// </returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public static bool operator !=(Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings left, Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings right)
        => !(left == right);

    /// <summary>
    /// Determines whether the left-hand side is greater than the right.
    /// </summary>
    /// <param name="left">The left-hand side.</param>
    /// <param name="right">The right-hand side.</param>
    /// <returns>
    /// The value determining whether the parameter <paramref name="left"/>
    /// is greater than the parameter <paramref name="right"/>.
    /// </returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public static bool operator >(Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings left, Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings right)
        => (left._discriminator == right._discriminator) && (left._discriminator
        switch
        {
            0 => false,
            1 => false,
            _ => throw new global::System.InvalidOperationException(),
        });

    /// <summary>
    /// Determines whether the left-hand side is greater than or equal to the right.
    /// </summary>
    /// <param name="left">The left-hand side.</param>
    /// <param name="right">The right-hand side.</param>
    /// <returns>
    /// The value determining whether the parameter <paramref name="left"/>
    /// is greater than or equal to the parameter <paramref name="right"/>.
    /// </returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public static bool operator >=(Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings left, Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings right)
        => left == right || left > right;

    /// <summary>
    /// Determines whether the left-hand side is less than the right.
    /// </summary>
    /// <param name="left">The left-hand side.</param>
    /// <param name="right">The right-hand side.</param>
    /// <returns>
    /// The value determining whether the parameter <paramref name="left"/>
    /// is less than the parameter <paramref name="right"/>.
    /// </returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public static bool operator <(Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings left, Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings right)
        => right > left;

    /// <summary>
    /// Determines whether the left-hand side is less than or equal to the right.
    /// </summary>
    /// <param name="left">The left-hand side.</param>
    /// <param name="right">The right-hand side.</param>
    /// <returns>
    /// The value determining whether the parameter <paramref name="left"/>
    /// is less than or equal to the parameter <paramref name="right"/>.
    /// </returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public static bool operator <=(Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings left, Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings right)
        => right >= left;

    /// <inheritdoc cref="object.Equals(object)"/>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public override bool Equals(object? obj)
        => false;

    /// <inheritdoc />
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public readonly bool Equals(Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings other)
        => this == other;

    /// <inheritdoc cref="IComparable.CompareTo(object)"/>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public readonly int CompareTo(object? obj)
        => -1;

    /// <inheritdoc />
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public readonly int CompareTo(Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings other)
        => Equals(other) ? 0 : -1;

    /// <inheritdoc />
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public readonly override int GetHashCode()
        => unchecked(_discriminator * 733879) ^
        (_discriminator switch
        {
            0 => Utf8.GetHashCode(),
            1 => Utf16.GetHashCode(),
            _ => throw new global::System.InvalidOperationException(),
        });

    /// <inheritdoc />
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public readonly override string ToString()
        => _discriminator switch
        {
            0 => $"{nameof(Utf8)}({Utf8.ToString()})",
            1 => $"{nameof(Utf16)}({Utf16.ToString()})",
            _ => throw new global::System.InvalidOperationException(),
        };

    /// <summary>
    /// Invokes the callback based on current variance.
    /// </summary>
    /// <param name="onUtf8">The callback to use when the contract of the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings"/> struct with the variant <see cref="Utf8"/> of type <see cref="System.Span{T}"/> is held.</param>
    /// <param name="onUtf16">The callback to use when the contract of the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings"/> struct with the variant <see cref="Utf16"/> of type <see cref="System.Span{T}"/> is held.</param>
    /// <returns>Itself.</returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public readonly Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings Map(
        Utf8Handler? onUtf8 = null,
        Utf16Handler? onUtf16 = null
    )
    {
        switch (_discriminator)
        {
            case 0:
                onUtf8?.Invoke(Utf8);
                return this;
            case 1:
                onUtf16?.Invoke(Utf16);
                return this;
            default: throw new global::System.InvalidOperationException();
        }
    }

    /// <summary>
    /// Maps each variant to <typeparamref name="TMappingResult"/>.
    /// </summary>
    /// <typeparam name="TMappingResult">The resulting type from the mapping.</typeparam>
    /// <param name="onUtf8">The callback to use when the contract of the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings"/> struct with the variant <see cref="Utf8"/> of type <see cref="System.Span{T}"/> is held.</param>
    /// <param name="onUtf16">The callback to use when the contract of the <see cref="Emik.SourceGenerators.Choices.Generated.Tests.SpanEncodings"/> struct with the variant <see cref="Utf16"/> of type <see cref="System.Span{T}"/> is held.</param>
    /// <returns>
    /// The resulting value from one of the parameters based on the current state of the object.
    /// </returns>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Diagnostics.Contracts.PureAttribute]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public readonly TMappingResult Map<TMappingResult>(
        Utf8Handler<TMappingResult> onUtf8,
        Utf16Handler<TMappingResult> onUtf16
    )
        => _discriminator
        switch
        {
            0 => onUtf8(Utf8),
            1 => onUtf16(Utf16),
            _ => throw new global::System.InvalidOperationException(),
        };

    /// <inheritdoc cref="System.Span{T}.Clear()"/>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public readonly void Clear()
    {
        switch (_discriminator)
        {
            case 0:
                _utf8.Clear();
                break;
            case 1:
                _utf16.Clear();
                break;
            default: throw new global::System.InvalidOperationException();
        }
    }

    /// <inheritdoc cref="System.Span{T}.IsEmpty"/>
    [global::System.CodeDom.Compiler.GeneratedCode("Emik.SourceGenerators.Choices", "1.0.0.0")]
    public readonly bool IsEmpty
    {
        [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
        get => _discriminator switch
        {
            0 => _utf8.IsEmpty,
            1 => _utf16.IsEmpty,
            _ => throw new global::System.InvalidOperationException(),
        };
    }
}

Contribute

Issues and pull requests are welcome to help this repository be the best it can be.

License

This repository falls under the MPL-2 license.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

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
1.4.0 149 9/30/2024
1.3.3 100 9/24/2024
1.3.2 105 9/6/2024
1.3.1 105 9/5/2024
1.3.0 129 8/11/2024
1.2.1 106 7/8/2024
1.2.0 315 11/12/2023
1.1.1 199 11/4/2023
1.1.0 250 11/4/2023
1.0.4 270 11/1/2023
1.0.3 208 10/31/2023
1.0.2 270 10/26/2023
1.0.1 228 10/23/2023
1.0.0 243 10/22/2023