Class BoxedValue<T>
Represents a typed representation of the boxed value type.
Inherited Members
Namespace: DotNext.Runtime
Assembly: DotNext.dll
Syntax
public abstract class BoxedValue<T> where T : struct
Type Parameters
| Name | Description |
|---|---|
| T | The value type. |
Remarks
Equals(object), GetHashCode() and ToString() implementations match to the real implementations of the appropriate value type. This type is completely compatible with runtime representation of the boxed value. For instance, the following code is correct:
static int Unbox(object obj) => (int)obj;
BoxedValue<int> boxed = BoxedValue<int>.Box(42);
int value = Unbox(boxed);
Additionally, it means that GetType() returns type information for T type,
not for BoxedValue<T>.
Constructors
View SourceBoxedValue()
Declaration
protected BoxedValue()
Methods
View SourceBox(T)
Converts a value type to an object reference.
Declaration
public static BoxedValue<T> Box(T value)
Parameters
| Type | Name | Description |
|---|---|---|
| T | value | The value to be boxed. |
Returns
| Type | Description |
|---|---|
| BoxedValue<T> | A boxed representation of the value. |
Equals(object?)
Declaration
public override abstract bool Equals(object? obj)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj |
Returns
| Type | Description |
|---|---|
| bool |
Overrides
View SourceGetHashCode()
Declaration
public override abstract int GetHashCode()
Returns
| Type | Description |
|---|---|
| int |
Overrides
View SourceGetTypedReference(object?)
Converts untyped reference to a boxed value into a typed reference.
Declaration
public static BoxedValue<T>? GetTypedReference(object? boxedValue)
Parameters
| Type | Name | Description |
|---|---|---|
| object | boxedValue | The boxed value of type |
Returns
| Type | Description |
|---|---|
| BoxedValue<T> | The typed reference to a boxed value of type |
Remarks
This method doesn't allocate memory.
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
|
ToString()
Declaration
public override abstract string ToString()
Returns
| Type | Description |
|---|---|
| string |
Overrides
View SourceTryBox(in T?)
Boxes nullable value type to an object.
Declaration
public static BoxedValue<T>? TryBox(in T? value)
Parameters
| Type | Name | Description |
|---|---|---|
| T? | value | The value to be boxed. |
Returns
| Type | Description |
|---|---|
| BoxedValue<T> | A boxed representation of the value. |
Operators
View Sourceexplicit operator BoxedValue<T>?(in T?)
Boxes nullable value type to an object.
Declaration
public static explicit operator BoxedValue<T>?(in T? value)
Parameters
| Type | Name | Description |
|---|---|---|
| T? | value | The value to be boxed. |
Returns
| Type | Description |
|---|---|
| BoxedValue<T> | A boxed representation of the value. |
explicit operator BoxedValue<T>(T)
Converts a value type to an object reference.
Declaration
public static explicit operator BoxedValue<T>(T value)
Parameters
| Type | Name | Description |
|---|---|---|
| T | value | The value to be boxed. |
Returns
| Type | Description |
|---|---|
| BoxedValue<T> | A boxed representation of the value. |
implicit operator ValueReference<T>(BoxedValue<T>)
Obtains a reference to the boxed value.
Declaration
public static implicit operator ValueReference<T>(BoxedValue<T> boxedValue)
Parameters
| Type | Name | Description |
|---|---|---|
| BoxedValue<T> | boxedValue | Boxed value. |
Returns
| Type | Description |
|---|---|
| ValueReference<T> | Mutable reference to the boxed value. |
implicit operator ValueType?(BoxedValue<T>?)
Converts a typed reference to a boxed value to untyped reference.
Declaration
public static implicit operator ValueType?(BoxedValue<T>? boxedValue)
Parameters
| Type | Name | Description |
|---|---|---|
| BoxedValue<T> | boxedValue | The boxed value. |
Returns
| Type | Description |
|---|---|
| ValueType | Untyped reference to a boxed value. |
implicit operator T(BoxedValue<T>)
Unboxes the value.
Declaration
public static implicit operator T(BoxedValue<T> boxedValue)
Parameters
| Type | Name | Description |
|---|---|---|
| BoxedValue<T> | boxedValue | The boxed representation of the value. |
Returns
| Type | Description |
|---|---|
| T |