Show / Hide Table of Contents

Class BoxedValue<T>

Represents a typed representation of the boxed value type.

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

Methods

| Edit this page 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.

| Edit this page View Source

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
object.Equals(object)
| Edit this page View Source

GetHashCode()

Serves as the default hash function.

Declaration
public override abstract int GetHashCode()
Returns
Type Description
int

A hash code for the current object.

Overrides
object.GetHashCode()
| Edit this page 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.

| Edit this page View Source

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
object.ToString()
| Edit this page 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

| Edit this page 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.

| Edit this page 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.

| Edit this page 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.

| Edit this page 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.

| Edit this page 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.GetUserData<T>(T)
BasicExtensions.IsBetween<T, TLowerBound, TUpperBound>(T, TLowerBound, TUpperBound)
BasicExtensions.IsOneOf<T>(T, ReadOnlySpan<T>)
ExpressionBuilder.Const<T>(T)
BoxedValue.Copy<T>(BoxedValue<T>)
BoxedValue.Unbox<T>(BoxedValue<T>)
AsyncLockAcquisition.AcquireLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireLockAsync<T>(T, TimeSpan, CancellationToken)
AsyncLockAcquisition.AcquireReadLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireReadLockAsync<T>(T, TimeSpan, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, bool, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, bool, TimeSpan, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, TimeSpan, CancellationToken)
LockAcquisition.AcquireReadLock<T>(T)
LockAcquisition.AcquireReadLock<T>(T, TimeSpan)
LockAcquisition.AcquireUpgradeableReadLock<T>(T)
LockAcquisition.AcquireUpgradeableReadLock<T>(T, TimeSpan)
LockAcquisition.AcquireWriteLock<T>(T)
LockAcquisition.AcquireWriteLock<T>(T, TimeSpan)
  • Edit this page
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾