Show / Hide Table of Contents

Struct Variant

Represents the variant value on the stack.

Implements
IEquatable<Variant>
Inherited Members
ValueType.Equals(object)
ValueType.GetHashCode()
ValueType.ToString()
object.GetType()
object.Equals(object, object)
object.ReferenceEquals(object, object)
Namespace: DotNext.Runtime
Assembly: DotNext.dll
Syntax
public readonly ref struct Variant : IEquatable<Variant>
Remarks

This type is a counterpart of TypedReference.

Properties

View Source

Empty

Gets empty value which IsEmpty is true.

Declaration
public static Variant Empty { get; }
Property Value
Type Description
Variant
View Source

IsEmpty

Gets a value indicating that this value is empty.

Declaration
public bool IsEmpty { get; }
Property Value
Type Description
bool
View Source

IsMutable

Gets a value indicating that the underlying value can be mutated.

Declaration
public bool IsMutable { get; }
Property Value
Type Description
bool
View Source

TargetType

Gets the type of the value.

Declaration
public Type TargetType { get; }
Property Value
Type Description
Type

Methods

View Source

Equals(scoped Variant)

Checks whether this container references the same value and type as other.

Declaration
public bool Equals(scoped Variant other)
Parameters
Type Name Description
Variant other

The value to compare.

Returns
Type Description
bool

true, if this container references the same value and type as other; otherwise, false.

View Source

Immutable<T>()

Gets the read-only reference to the underlying value.

Declaration
public ref readonly T Immutable<T>() where T : allows ref struct
Returns
Type Description
T

A location of the value.

Type Parameters
Name Description
T

The expected type of the value.

Exceptions
Type Condition
InvalidCastException

The underlying value cannot be converted to type T.

View Source

Immutable<T>(ref readonly T)

Creates immutable value and stores its type.

Declaration
public static Variant Immutable<T>(ref readonly T location) where T : allows ref struct
Parameters
Type Name Description
T location

The location of the value.

Returns
Type Description
Variant

The untyped value.

Type Parameters
Name Description
T

The type of the value.

View Source

Mutable(ValueType)

Creates mutable boxed value and stores its type.

Declaration
public static Variant Mutable(ValueType boxedValue)
Parameters
Type Name Description
ValueType boxedValue

The boxed value.

Returns
Type Description
Variant

The boxed value.

View Source

Mutable<T>()

Tries to get the mutable reference to the underlying value.

Declaration
public ref T Mutable<T>() where T : allows ref struct
Returns
Type Description
T

A location of the value.

Type Parameters
Name Description
T

The expected type of the value.

Exceptions
Type Condition
InvalidCastException

The underlying value cannot be converted to type T; or it is not mutable.

View Source

Mutable<T>(ref T)

Creates mutable value and stores its type.

Declaration
public static Variant Mutable<T>(ref T location) where T : allows ref struct
Parameters
Type Name Description
T location

The location of the value.

Returns
Type Description
Variant

The untyped value.

Type Parameters
Name Description
T

The type of the value.

View Source

ToObject()

Tries to extract the underlying value.

Declaration
public object? ToObject()
Returns
Type Description
object

The underlying value.

Exceptions
Type Condition
NotSupportedException

The underlying value is by-ref like struct and cannot be boxed.

Operators

View Source

operator ==(Variant, Variant)

Determines whether the two containers reference the same value and type.

Declaration
public static bool operator ==(Variant x, Variant y)
Parameters
Type Name Description
Variant x

The first container to compare.

Variant y

The second container to compare.

Returns
Type Description
bool

true if both containers reference the same value and type; otherwise, false.

View Source

operator !=(Variant, Variant)

Determines whether the two containers reference the different values and types.

Declaration
public static bool operator !=(Variant x, Variant y)
Parameters
Type Name Description
Variant x

The first container to compare.

Variant y

The second container to compare.

Returns
Type Description
bool

true if both containers reference the different values and types; otherwise, false.

Implements

IEquatable<T>

Extension Methods

BasicExtensions.IsBetween<T, TLowerBound, TUpperBound>(T, TLowerBound, TUpperBound)
Enumerator.Skip<TEnumerator, T>(ref TEnumerator, int)
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾