Struct Variant
Represents the variant value on the stack.
Implements
Inherited Members
Namespace: DotNext.Runtime
Assembly: DotNext.dll
Syntax
public readonly ref struct Variant : IEquatable<Variant>
Remarks
This type is a counterpart of TypedReference.
Properties
View SourceEmpty
Declaration
public static Variant Empty { get; }
Property Value
| Type | Description |
|---|---|
| Variant |
IsEmpty
Gets a value indicating that this value is empty.
Declaration
public bool IsEmpty { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsMutable
Gets a value indicating that the underlying value can be mutated.
Declaration
public bool IsMutable { get; }
Property Value
| Type | Description |
|---|---|
| bool |
TargetType
Gets the type of the value.
Declaration
public Type TargetType { get; }
Property Value
| Type | Description |
|---|---|
| Type |
Methods
View SourceEquals(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 |
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 |
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. |
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. |
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 |
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. |
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 Sourceoperator ==(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. |
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. |