Table of Contents

Struct OneOf<T1, T2, T3, T4, T5, T6, T7, T8>

Namespace
Utils.Objects
Assembly
Utils.dll

Represents a discriminated union that can hold a value of T1, T2, T3, T4, T5, T6, T7 or T8.

public readonly struct OneOf<T1, T2, T3, T4, T5, T6, T7, T8> : IEqualityOperators<OneOf<T1, T2, T3, T4, T5, T6, T7, T8>, OneOf<T1, T2, T3, T4, T5, T6, T7, T8>, bool>

Type Parameters

T1

The first possible value type.

T2

The second possible value type.

T3

The third possible value type.

T4

The fourth possible value type.

T5

The fifth possible value type.

T6

The sixth possible value type.

T7

The seventh possible value type.

T8

The eighth possible value type.

Implements
IEqualityOperators<OneOf<T1, T2, T3, T4, T5, T6, T7, T8>, OneOf<T1, T2, T3, T4, T5, T6, T7, T8>, bool>
Inherited Members
Extension Methods

Methods

Equals(object?)

Determines whether the stored value equals the specified object.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the stored value.

Returns

bool

true when the stored value equals obj; otherwise, false.

GetHashCode()

Returns the hash code of the stored value.

public override int GetHashCode()

Returns

int

The hash code of the stored value, or 0 when no value is stored.

Switch(Action<T1>, Action<T2>, Action<T3>, Action<T4>, Action<T5>, Action<T6>, Action<T7>, Action<T8>)

Executes one of the provided actions depending on the stored value type.

public void Switch(Action<T1> action1, Action<T2> action2, Action<T3> action3, Action<T4> action4, Action<T5> action5, Action<T6> action6, Action<T7> action7, Action<T8> action8)

Parameters

action1 Action<T1>

The action to invoke when the stored value is of type T1.

action2 Action<T2>

The action to invoke when the stored value is of type T2.

action3 Action<T3>

The action to invoke when the stored value is of type T3.

action4 Action<T4>

The action to invoke when the stored value is of type T4.

action5 Action<T5>

The action to invoke when the stored value is of type T5.

action6 Action<T6>

The action to invoke when the stored value is of type T6.

action7 Action<T7>

The action to invoke when the stored value is of type T7.

action8 Action<T8>

The action to invoke when the stored value is of type T8.

Switch<T>(Func<T1, T>, Func<T2, T>, Func<T3, T>, Func<T4, T>, Func<T5, T>, Func<T6, T>, Func<T7, T>, Func<T8, T>)

Projects the stored value using the provided functions.

public T Switch<T>(Func<T1, T> func1, Func<T2, T> func2, Func<T3, T> func3, Func<T4, T> func4, Func<T5, T> func5, Func<T6, T> func6, Func<T7, T> func7, Func<T8, T> func8)

Parameters

func1 Func<T1, T>

The function to use when the stored value is of type T1.

func2 Func<T2, T>

The function to use when the stored value is of type T2.

func3 Func<T3, T>

The function to use when the stored value is of type T3.

func4 Func<T4, T>

The function to use when the stored value is of type T4.

func5 Func<T5, T>

The function to use when the stored value is of type T5.

func6 Func<T6, T>

The function to use when the stored value is of type T6.

func7 Func<T7, T>

The function to use when the stored value is of type T7.

func8 Func<T8, T>

The function to use when the stored value is of type T8.

Returns

T

The result produced by the matching projection function, or the default value of T when the corresponding function is null.

Type Parameters

T

The return type of the projection.

ToString()

Returns a string representation of the stored value.

public override string ToString()

Returns

string

The result of calling ToString() on the stored value, or Empty when no value is stored.

Operators

operator ==(OneOf<T1, T2, T3, T4, T5, T6, T7, T8>, OneOf<T1, T2, T3, T4, T5, T6, T7, T8>)

Determines whether two instances store equal values.

public static bool operator ==(OneOf<T1, T2, T3, T4, T5, T6, T7, T8> left, OneOf<T1, T2, T3, T4, T5, T6, T7, T8> right)

Parameters

left OneOf<T1, T2, T3, T4, T5, T6, T7, T8>

The first instance to compare.

right OneOf<T1, T2, T3, T4, T5, T6, T7, T8>

The second instance to compare.

Returns

bool

true when both instances store equal values; otherwise, false.

implicit operator T1(OneOf<T1, T2, T3, T4, T5, T6, T7, T8>)

Retrieves the stored T1 value.

public static implicit operator T1(OneOf<T1, T2, T3, T4, T5, T6, T7, T8> oo)

Parameters

oo OneOf<T1, T2, T3, T4, T5, T6, T7, T8>

The union to convert.

Returns

T1

The stored value when it is of type T1.

implicit operator T2(OneOf<T1, T2, T3, T4, T5, T6, T7, T8>)

Retrieves the stored T2 value.

public static implicit operator T2(OneOf<T1, T2, T3, T4, T5, T6, T7, T8> oo)

Parameters

oo OneOf<T1, T2, T3, T4, T5, T6, T7, T8>

The union to convert.

Returns

T2

The stored value when it is of type T2.

implicit operator T3(OneOf<T1, T2, T3, T4, T5, T6, T7, T8>)

Retrieves the stored T3 value.

public static implicit operator T3(OneOf<T1, T2, T3, T4, T5, T6, T7, T8> oo)

Parameters

oo OneOf<T1, T2, T3, T4, T5, T6, T7, T8>

The union to convert.

Returns

T3

The stored value when it is of type T3.

implicit operator T4(OneOf<T1, T2, T3, T4, T5, T6, T7, T8>)

Retrieves the stored T4 value.

public static implicit operator T4(OneOf<T1, T2, T3, T4, T5, T6, T7, T8> oo)

Parameters

oo OneOf<T1, T2, T3, T4, T5, T6, T7, T8>

The union to convert.

Returns

T4

The stored value when it is of type T4.

implicit operator T5(OneOf<T1, T2, T3, T4, T5, T6, T7, T8>)

Retrieves the stored T5 value.

public static implicit operator T5(OneOf<T1, T2, T3, T4, T5, T6, T7, T8> oo)

Parameters

oo OneOf<T1, T2, T3, T4, T5, T6, T7, T8>

The union to convert.

Returns

T5

The stored value when it is of type T5.

implicit operator T6(OneOf<T1, T2, T3, T4, T5, T6, T7, T8>)

Retrieves the stored T6 value.

public static implicit operator T6(OneOf<T1, T2, T3, T4, T5, T6, T7, T8> oo)

Parameters

oo OneOf<T1, T2, T3, T4, T5, T6, T7, T8>

The union to convert.

Returns

T6

The stored value when it is of type T6.

implicit operator T7(OneOf<T1, T2, T3, T4, T5, T6, T7, T8>)

Retrieves the stored T7 value.

public static implicit operator T7(OneOf<T1, T2, T3, T4, T5, T6, T7, T8> oo)

Parameters

oo OneOf<T1, T2, T3, T4, T5, T6, T7, T8>

The union to convert.

Returns

T7

The stored value when it is of type T7.

implicit operator T8(OneOf<T1, T2, T3, T4, T5, T6, T7, T8>)

Retrieves the stored T8 value.

public static implicit operator T8(OneOf<T1, T2, T3, T4, T5, T6, T7, T8> oo)

Parameters

oo OneOf<T1, T2, T3, T4, T5, T6, T7, T8>

The union to convert.

Returns

T8

The stored value when it is of type T8.

implicit operator OneOf<T1, T2, T3, T4, T5, T6, T7, T8>(T1)

Creates a OneOf<T1, T2, T3, T4, T5, T6, T7, T8> from a T1 value.

public static implicit operator OneOf<T1, T2, T3, T4, T5, T6, T7, T8>(T1 o)

Parameters

o T1

The value to wrap.

Returns

OneOf<T1, T2, T3, T4, T5, T6, T7, T8>

A OneOf<T1, T2, T3, T4, T5, T6, T7, T8> instance storing o.

implicit operator OneOf<T1, T2, T3, T4, T5, T6, T7, T8>(T2)

Creates a OneOf<T1, T2, T3, T4, T5, T6, T7, T8> from a T2 value.

public static implicit operator OneOf<T1, T2, T3, T4, T5, T6, T7, T8>(T2 o)

Parameters

o T2

The value to wrap.

Returns

OneOf<T1, T2, T3, T4, T5, T6, T7, T8>

A OneOf<T1, T2, T3, T4, T5, T6, T7, T8> instance storing o.

implicit operator OneOf<T1, T2, T3, T4, T5, T6, T7, T8>(T3)

Creates a OneOf<T1, T2, T3, T4, T5, T6, T7, T8> from a T3 value.

public static implicit operator OneOf<T1, T2, T3, T4, T5, T6, T7, T8>(T3 o)

Parameters

o T3

The value to wrap.

Returns

OneOf<T1, T2, T3, T4, T5, T6, T7, T8>

A OneOf<T1, T2, T3, T4, T5, T6, T7, T8> instance storing o.

implicit operator OneOf<T1, T2, T3, T4, T5, T6, T7, T8>(T4)

Creates a OneOf<T1, T2, T3, T4, T5, T6, T7, T8> from a T4 value.

public static implicit operator OneOf<T1, T2, T3, T4, T5, T6, T7, T8>(T4 o)

Parameters

o T4

The value to wrap.

Returns

OneOf<T1, T2, T3, T4, T5, T6, T7, T8>

A OneOf<T1, T2, T3, T4, T5, T6, T7, T8> instance storing o.

implicit operator OneOf<T1, T2, T3, T4, T5, T6, T7, T8>(T5)

Creates a OneOf<T1, T2, T3, T4, T5, T6, T7, T8> from a T5 value.

public static implicit operator OneOf<T1, T2, T3, T4, T5, T6, T7, T8>(T5 o)

Parameters

o T5

The value to wrap.

Returns

OneOf<T1, T2, T3, T4, T5, T6, T7, T8>

A OneOf<T1, T2, T3, T4, T5, T6, T7, T8> instance storing o.

implicit operator OneOf<T1, T2, T3, T4, T5, T6, T7, T8>(T6)

Creates a OneOf<T1, T2, T3, T4, T5, T6, T7, T8> from a T6 value.

public static implicit operator OneOf<T1, T2, T3, T4, T5, T6, T7, T8>(T6 o)

Parameters

o T6

The value to wrap.

Returns

OneOf<T1, T2, T3, T4, T5, T6, T7, T8>

A OneOf<T1, T2, T3, T4, T5, T6, T7, T8> instance storing o.

implicit operator OneOf<T1, T2, T3, T4, T5, T6, T7, T8>(T7)

Creates a OneOf<T1, T2, T3, T4, T5, T6, T7, T8> from a T7 value.

public static implicit operator OneOf<T1, T2, T3, T4, T5, T6, T7, T8>(T7 o)

Parameters

o T7

The value to wrap.

Returns

OneOf<T1, T2, T3, T4, T5, T6, T7, T8>

A OneOf<T1, T2, T3, T4, T5, T6, T7, T8> instance storing o.

implicit operator OneOf<T1, T2, T3, T4, T5, T6, T7, T8>(T8)

Creates a OneOf<T1, T2, T3, T4, T5, T6, T7, T8> from a T8 value.

public static implicit operator OneOf<T1, T2, T3, T4, T5, T6, T7, T8>(T8 o)

Parameters

o T8

The value to wrap.

Returns

OneOf<T1, T2, T3, T4, T5, T6, T7, T8>

A OneOf<T1, T2, T3, T4, T5, T6, T7, T8> instance storing o.

operator !=(OneOf<T1, T2, T3, T4, T5, T6, T7, T8>, OneOf<T1, T2, T3, T4, T5, T6, T7, T8>)

Determines whether two instances store different values.

public static bool operator !=(OneOf<T1, T2, T3, T4, T5, T6, T7, T8> left, OneOf<T1, T2, T3, T4, T5, T6, T7, T8> right)

Parameters

left OneOf<T1, T2, T3, T4, T5, T6, T7, T8>

The first instance to compare.

right OneOf<T1, T2, T3, T4, T5, T6, T7, T8>

The second instance to compare.

Returns

bool

true when the instances store different values; otherwise, false.