Show / Hide Table of Contents

    Class Variant<T1, T2, T3, T4, T5, T6, T7, T8>

    Represents a 8-type discriminate union.
    Inheritance
    System.Object
    VariantBase
    Variant<T1, T2, T3, T4, T5, T6, T7, T8>
    Inherited Members
    VariantBase.Index
    VariantBase.Is<T>()
    VariantBase.Get<T>()
    VariantBase.Get()
    VariantBase.Equals(Object)
    VariantBase.GetHashCode()
    System.Object.Equals(System.Object, System.Object)
    System.Object.GetType()
    System.Object.MemberwiseClone()
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.ToString()
    Namespace: Maki
    Assembly: Maki.dll
    Syntax
    public sealed class Variant<T1, T2, T3, T4, T5, T6, T7, T8> : VariantBase
    Type Parameters
    Name Description
    T1 Represents the variant's first type.
    T2 Represents the variant's second type.
    T3 Represents the variant's third type.
    T4 Represents the variant's fourth type.
    T5 Represents the variant's fifth type.
    T6 Represents the variant's sixth type.
    T7 Represents the variant's seventh type.
    T8 Represents the variant's eighth type.
    Examples
    The following example shows how to assign values of different types to a Variant and how to extract values from it.
    using Maki;
    using System;
    
    namespace Samples
    {
        class Program
        {
            static void Main(string[] args)
            {
                // A variant can hold a value of any of its generic types
                Variant<int, string, double> variant = 42;
    
                // Depending on the type of the value currently inhabiting the variant,
                // the right Action gets executed
                variant.Apply(
                    i => Console.WriteLine(i * 2),
                    s => Console.WriteLine(s + "!"),
                    d => Console.WriteLine($"Double: {d}")
                );
    
                // Can reassign variant with another of its generic types
                variant = "Hello world";
    
                // Check the type of the value currently inhabiting the variant
                if (variant.Is<string>())
                {
                    // Extract a string from the variant
                    Console.WriteLine($"The string is: {variant.Get<string>()}");
                }
            }
        }
    }

    Constructors

    | Improve this Doc View Source

    Variant(T1)

    Creates a new Variant instance from an item of type T1.
    Declaration
    public Variant(T1 item)
    Parameters
    Type Name Description
    T1 item Item of type T1.
    | Improve this Doc View Source

    Variant(T2)

    Creates a new Variant instance from an item of type T2.
    Declaration
    public Variant(T2 item)
    Parameters
    Type Name Description
    T2 item Item of type T2.
    | Improve this Doc View Source

    Variant(T3)

    Creates a new Variant instance from an item of type T3.
    Declaration
    public Variant(T3 item)
    Parameters
    Type Name Description
    T3 item Item of type T3.
    | Improve this Doc View Source

    Variant(T4)

    Creates a new Variant instance from an item of type T4.
    Declaration
    public Variant(T4 item)
    Parameters
    Type Name Description
    T4 item Item of type T4.
    | Improve this Doc View Source

    Variant(T5)

    Creates a new Variant instance from an item of type T5.
    Declaration
    public Variant(T5 item)
    Parameters
    Type Name Description
    T5 item Item of type T5.
    | Improve this Doc View Source

    Variant(T6)

    Creates a new Variant instance from an item of type T6.
    Declaration
    public Variant(T6 item)
    Parameters
    Type Name Description
    T6 item Item of type T6.
    | Improve this Doc View Source

    Variant(T7)

    Creates a new Variant instance from an item of type T7.
    Declaration
    public Variant(T7 item)
    Parameters
    Type Name Description
    T7 item Item of type T7.
    | Improve this Doc View Source

    Variant(T8)

    Creates a new Variant instance from an item of type T8.
    Declaration
    public Variant(T8 item)
    Parameters
    Type Name Description
    T8 item Item of type T8.

    Methods

    | Improve this Doc View Source

    Make1(T1)

    Creates a new Variant explicitly placing the item as the first type (T1).
    Declaration
    public static Variant<T1, T2, T3, T4, T5, T6, T7, T8> Make1(T1 item)
    Parameters
    Type Name Description
    T1 item Item to place in the variant.
    Returns
    Type Description
    Variant<T1, T2, T3, T4, T5, T6, T7, T8> New Variant instance.
    Remarks
    Use this method when the variant contains multiple instances of the same type. This allows explicit placing of the item.
    | Improve this Doc View Source

    Make2(T2)

    Creates a new Variant explicitly placing the item as the second type (T2).
    Declaration
    public static Variant<T1, T2, T3, T4, T5, T6, T7, T8> Make2(T2 item)
    Parameters
    Type Name Description
    T2 item Item to place in the variant.
    Returns
    Type Description
    Variant<T1, T2, T3, T4, T5, T6, T7, T8> New Variant instance.
    Remarks
    Use this method when the variant contains multiple instances of the same type. This allows explicit placing of the item.
    | Improve this Doc View Source

    Make3(T3)

    Creates a new Variant explicitly placing the item as the third type (T3).
    Declaration
    public static Variant<T1, T2, T3, T4, T5, T6, T7, T8> Make3(T3 item)
    Parameters
    Type Name Description
    T3 item Item to place in the variant.
    Returns
    Type Description
    Variant<T1, T2, T3, T4, T5, T6, T7, T8> New Variant instance.
    Remarks
    Use this method when the variant contains multiple instances of the same type. This allows explicit placing of the item.
    | Improve this Doc View Source

    Make4(T4)

    Creates a new Variant explicitly placing the item as the fourth type (T4).
    Declaration
    public static Variant<T1, T2, T3, T4, T5, T6, T7, T8> Make4(T4 item)
    Parameters
    Type Name Description
    T4 item Item to place in the variant.
    Returns
    Type Description
    Variant<T1, T2, T3, T4, T5, T6, T7, T8> New Variant instance.
    Remarks
    Use this method when the variant contains multiple instances of the same type. This allows explicit placing of the item.
    | Improve this Doc View Source

    Make5(T5)

    Creates a new Variant explicitly placing the item as the fifth type (T5).
    Declaration
    public static Variant<T1, T2, T3, T4, T5, T6, T7, T8> Make5(T5 item)
    Parameters
    Type Name Description
    T5 item Item to place in the variant.
    Returns
    Type Description
    Variant<T1, T2, T3, T4, T5, T6, T7, T8> New Variant instance.
    Remarks
    Use this method when the variant contains multiple instances of the same type. This allows explicit placing of the item.
    | Improve this Doc View Source

    Make6(T6)

    Creates a new Variant explicitly placing the item as the sixth type (T6).
    Declaration
    public static Variant<T1, T2, T3, T4, T5, T6, T7, T8> Make6(T6 item)
    Parameters
    Type Name Description
    T6 item Item to place in the variant.
    Returns
    Type Description
    Variant<T1, T2, T3, T4, T5, T6, T7, T8> New Variant instance.
    Remarks
    Use this method when the variant contains multiple instances of the same type. This allows explicit placing of the item.
    | Improve this Doc View Source

    Make7(T7)

    Creates a new Variant explicitly placing the item as the seventh type (T7).
    Declaration
    public static Variant<T1, T2, T3, T4, T5, T6, T7, T8> Make7(T7 item)
    Parameters
    Type Name Description
    T7 item Item to place in the variant.
    Returns
    Type Description
    Variant<T1, T2, T3, T4, T5, T6, T7, T8> New Variant instance.
    Remarks
    Use this method when the variant contains multiple instances of the same type. This allows explicit placing of the item.
    | Improve this Doc View Source

    Make8(T8)

    Creates a new Variant explicitly placing the item as the eighth type (T8).
    Declaration
    public static Variant<T1, T2, T3, T4, T5, T6, T7, T8> Make8(T8 item)
    Parameters
    Type Name Description
    T8 item Item to place in the variant.
    Returns
    Type Description
    Variant<T1, T2, T3, T4, T5, T6, T7, T8> New Variant instance.
    Remarks
    Use this method when the variant contains multiple instances of the same type. This allows explicit placing of the item.

    Operators

    | Improve this Doc View Source

    Explicit(Variant<T1, T2, T3, T4, T5, T6, T7, T8> to T1)

    Explicitly casts from variant to T1.
    Declaration
    public static explicit operator T1(Variant<T1, T2, T3, T4, T5, T6, T7, T8> variant)
    Parameters
    Type Name Description
    Variant<T1, T2, T3, T4, T5, T6, T7, T8> variant Variant to cast to T1.
    Returns
    Type Description
    T1
    Exceptions
    Type Condition
    System.InvalidCastException Thrown if the item inhabiting the variant is not of type
    | Improve this Doc View Source

    Explicit(Variant<T1, T2, T3, T4, T5, T6, T7, T8> to T2)

    Explicitly casts from variant to T2.
    Declaration
    public static explicit operator T2(Variant<T1, T2, T3, T4, T5, T6, T7, T8> variant)
    Parameters
    Type Name Description
    Variant<T1, T2, T3, T4, T5, T6, T7, T8> variant Variant to cast to T2.
    Returns
    Type Description
    T2
    Exceptions
    Type Condition
    System.InvalidCastException Thrown if the item inhabiting the variant is not of type
    | Improve this Doc View Source

    Explicit(Variant<T1, T2, T3, T4, T5, T6, T7, T8> to T3)

    Explicitly casts from variant to T3.
    Declaration
    public static explicit operator T3(Variant<T1, T2, T3, T4, T5, T6, T7, T8> variant)
    Parameters
    Type Name Description
    Variant<T1, T2, T3, T4, T5, T6, T7, T8> variant Variant to cast to T3.
    Returns
    Type Description
    T3
    Exceptions
    Type Condition
    System.InvalidCastException Thrown if the item inhabiting the variant is not of type
    | Improve this Doc View Source

    Explicit(Variant<T1, T2, T3, T4, T5, T6, T7, T8> to T4)

    Explicitly casts from variant to T4.
    Declaration
    public static explicit operator T4(Variant<T1, T2, T3, T4, T5, T6, T7, T8> variant)
    Parameters
    Type Name Description
    Variant<T1, T2, T3, T4, T5, T6, T7, T8> variant Variant to cast to T4.
    Returns
    Type Description
    T4
    Exceptions
    Type Condition
    System.InvalidCastException Thrown if the item inhabiting the variant is not of type
    | Improve this Doc View Source

    Explicit(Variant<T1, T2, T3, T4, T5, T6, T7, T8> to T5)

    Explicitly casts from variant to T5.
    Declaration
    public static explicit operator T5(Variant<T1, T2, T3, T4, T5, T6, T7, T8> variant)
    Parameters
    Type Name Description
    Variant<T1, T2, T3, T4, T5, T6, T7, T8> variant Variant to cast to T5.
    Returns
    Type Description
    T5
    Exceptions
    Type Condition
    System.InvalidCastException Thrown if the item inhabiting the variant is not of type
    | Improve this Doc View Source

    Explicit(Variant<T1, T2, T3, T4, T5, T6, T7, T8> to T6)

    Explicitly casts from variant to T6.
    Declaration
    public static explicit operator T6(Variant<T1, T2, T3, T4, T5, T6, T7, T8> variant)
    Parameters
    Type Name Description
    Variant<T1, T2, T3, T4, T5, T6, T7, T8> variant Variant to cast to T6.
    Returns
    Type Description
    T6
    Exceptions
    Type Condition
    System.InvalidCastException Thrown if the item inhabiting the variant is not of type
    | Improve this Doc View Source

    Explicit(Variant<T1, T2, T3, T4, T5, T6, T7, T8> to T7)

    Explicitly casts from variant to T7.
    Declaration
    public static explicit operator T7(Variant<T1, T2, T3, T4, T5, T6, T7, T8> variant)
    Parameters
    Type Name Description
    Variant<T1, T2, T3, T4, T5, T6, T7, T8> variant Variant to cast to T7.
    Returns
    Type Description
    T7
    Exceptions
    Type Condition
    System.InvalidCastException Thrown if the item inhabiting the variant is not of type
    | Improve this Doc View Source

    Explicit(Variant<T1, T2, T3, T4, T5, T6, T7, T8> to T8)

    Explicitly casts from variant to T8.
    Declaration
    public static explicit operator T8(Variant<T1, T2, T3, T4, T5, T6, T7, T8> variant)
    Parameters
    Type Name Description
    Variant<T1, T2, T3, T4, T5, T6, T7, T8> variant Variant to cast to T8.
    Returns
    Type Description
    T8
    Exceptions
    Type Condition
    System.InvalidCastException Thrown if the item inhabiting the variant is not of type
    | Improve this Doc View Source

    Implicit(T1 to Variant<T1, T2, T3, T4, T5, T6, T7, T8>)

    Implicitly casts from T1 to variant. Creates a new Variant inhabited by the given item.
    Declaration
    public static implicit operator Variant<T1, T2, T3, T4, T5, T6, T7, T8>(T1 item)
    Parameters
    Type Name Description
    T1 item Item to store in the variant.
    Returns
    Type Description
    Variant<T1, T2, T3, T4, T5, T6, T7, T8>
    | Improve this Doc View Source

    Implicit(T2 to Variant<T1, T2, T3, T4, T5, T6, T7, T8>)

    Implicitly casts from T2 to variant. Creates a new Variant inhabited by the given item.
    Declaration
    public static implicit operator Variant<T1, T2, T3, T4, T5, T6, T7, T8>(T2 item)
    Parameters
    Type Name Description
    T2 item Item to store in the variant.
    Returns
    Type Description
    Variant<T1, T2, T3, T4, T5, T6, T7, T8>
    | Improve this Doc View Source

    Implicit(T3 to Variant<T1, T2, T3, T4, T5, T6, T7, T8>)

    Implicitly casts from T3 to variant. Creates a new Variant inhabited by the given item.
    Declaration
    public static implicit operator Variant<T1, T2, T3, T4, T5, T6, T7, T8>(T3 item)
    Parameters
    Type Name Description
    T3 item Item to store in the variant.
    Returns
    Type Description
    Variant<T1, T2, T3, T4, T5, T6, T7, T8>
    | Improve this Doc View Source

    Implicit(T4 to Variant<T1, T2, T3, T4, T5, T6, T7, T8>)

    Implicitly casts from T4 to variant. Creates a new Variant inhabited by the given item.
    Declaration
    public static implicit operator Variant<T1, T2, T3, T4, T5, T6, T7, T8>(T4 item)
    Parameters
    Type Name Description
    T4 item Item to store in the variant.
    Returns
    Type Description
    Variant<T1, T2, T3, T4, T5, T6, T7, T8>
    | Improve this Doc View Source

    Implicit(T5 to Variant<T1, T2, T3, T4, T5, T6, T7, T8>)

    Implicitly casts from T5 to variant. Creates a new Variant inhabited by the given item.
    Declaration
    public static implicit operator Variant<T1, T2, T3, T4, T5, T6, T7, T8>(T5 item)
    Parameters
    Type Name Description
    T5 item Item to store in the variant.
    Returns
    Type Description
    Variant<T1, T2, T3, T4, T5, T6, T7, T8>
    | Improve this Doc View Source

    Implicit(T6 to Variant<T1, T2, T3, T4, T5, T6, T7, T8>)

    Implicitly casts from T6 to variant. Creates a new Variant inhabited by the given item.
    Declaration
    public static implicit operator Variant<T1, T2, T3, T4, T5, T6, T7, T8>(T6 item)
    Parameters
    Type Name Description
    T6 item Item to store in the variant.
    Returns
    Type Description
    Variant<T1, T2, T3, T4, T5, T6, T7, T8>
    | Improve this Doc View Source

    Implicit(T7 to Variant<T1, T2, T3, T4, T5, T6, T7, T8>)

    Implicitly casts from T7 to variant. Creates a new Variant inhabited by the given item.
    Declaration
    public static implicit operator Variant<T1, T2, T3, T4, T5, T6, T7, T8>(T7 item)
    Parameters
    Type Name Description
    T7 item Item to store in the variant.
    Returns
    Type Description
    Variant<T1, T2, T3, T4, T5, T6, T7, T8>
    | Improve this Doc View Source

    Implicit(T8 to Variant<T1, T2, T3, T4, T5, T6, T7, T8>)

    Implicitly casts from T8 to variant. Creates a new Variant inhabited by the given item.
    Declaration
    public static implicit operator Variant<T1, T2, T3, T4, T5, T6, T7, T8>(T8 item)
    Parameters
    Type Name Description
    T8 item Item to store in the variant.
    Returns
    Type Description
    Variant<T1, T2, T3, T4, T5, T6, T7, T8>

    Extension Methods

    VariantExtensions.Map<T1, T2, T3, T4, T5, T6, T7, T8, U1, U2, U3, U4, U5, U6, U7, U8>(Variant<T1, T2, T3, T4, T5, T6, T7, T8>, Func<T1, U1>, Func<T2, U2>, Func<T3, U3>, Func<T4, U4>, Func<T5, U5>, Func<T6, U6>, Func<T7, U7>, Func<T8, U8>)
    VariantExtensions.Apply<T1, T2, T3, T4, T5, T6, T7, T8, U>(Variant<T1, T2, T3, T4, T5, T6, T7, T8>, Func<T1, U>, Func<T2, U>, Func<T3, U>, Func<T4, U>, Func<T5, U>, Func<T6, U>, Func<T7, U>, Func<T8, U>)
    VariantExtensions.Apply<T1, T2, T3, T4, T5, T6, T7, T8>(Variant<T1, T2, T3, T4, T5, T6, T7, T8>, Action<T1>, Action<T2>, Action<T3>, Action<T4>, Action<T5>, Action<T6>, Action<T7>, Action<T8>)
    • Improve this Doc
    • View Source
    Back to top Generated by DocFX