Show / Hide Table of Contents

Class BoxedValue<T>

Represents a typed representation of the boxed value type.

Inheritance
object
BoxedValue<T>
Inherited Members
object.GetType()
object.MemberwiseClone()
object.Equals(object, object)
object.ReferenceEquals(object, object)
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 Source

BoxedValue()

Declaration
protected BoxedValue()

Methods

View Source

Box(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.

View Source

Equals(object?)

Declaration
public override abstract bool Equals(object? obj)
Parameters
Type Name Description
object obj
Returns
Type Description
bool
Overrides
object.Equals(object)
View Source

GetHashCode()

Declaration
public override abstract int GetHashCode()
Returns
Type Description
int
Overrides
object.GetHashCode()
View Source

GetTypedReference(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 T.

Returns
Type Description
BoxedValue<T>

The typed reference to a boxed value of type T.

Remarks

This method doesn't allocate memory.

Exceptions
Type Condition
ArgumentException

boxedValue is not of type T.

View Source

ToString()

Declaration
public override abstract string ToString()
Returns
Type Description
string
Overrides
object.ToString()
View Source

TryBox(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 Source

explicit 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.

View Source

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.

View Source

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.

View Source

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.

View Source

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

Extension Methods

BasicExtensions.As<T>(T)
BasicExtensions.IsBetween<T, TLowerBound, TUpperBound>(T, TLowerBound, TUpperBound)
BasicExtensions.IsOneOf<T>(T, params ReadOnlySpan<T>)
BoxedValue.Copy<T>(BoxedValue<T>)
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾