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>.
Methods
| Edit this page 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?)
Determines whether the specified object is equal to the current object.
Declaration
public override abstract bool Equals(object? obj)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj | The object to compare with the current object. |
Returns
| Type | Description |
|---|---|
| bool | true if the specified object is equal to the current object; otherwise, false. |
Overrides
| Edit this page View SourceGetHashCode()
Serves as the default hash function.
Declaration
public override abstract int GetHashCode()
Returns
| Type | Description |
|---|---|
| int | A hash code for the current object. |
Overrides
| Edit this page 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()
Returns a string that represents the current object.
Declaration
public override abstract string ToString()
Returns
| Type | Description |
|---|---|
| string | A string that represents the current object. |
Overrides
| Edit this page 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
| Edit this page 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 |