Show / Hide Table of Contents

Class AdvancedHelpers

Represents advanced helpers.

Inheritance
object
AdvancedHelpers
Inherited Members
object.GetType()
object.MemberwiseClone()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: DotNext.Runtime.CompilerServices
Assembly: DotNext.dll
Syntax
public static class AdvancedHelpers

Methods

View Source

AddressOf<T>(ref readonly T)

Returns an address of the given by-ref parameter.

Declaration
public static nint AddressOf<T>(ref readonly T value) where T : allows ref struct
Parameters
Type Name Description
T value

The object whose address is obtained.

Returns
Type Description
nint

An address of the given object.

Type Parameters
Name Description
T

The type of object.

View Source

AlignOf<T>()

Gets the alignment requirement for type T, in bytes.

Declaration
public static int AlignOf<T>() where T : allows ref struct
Returns
Type Description
int

The alignment of the type T.

Type Parameters
Name Description
T

The target type.

See Also
_Alignof operator in C++
View Source

AreCompatible<T1, T2>()

Determines whether the two types are binary compatible, i.e. both types have the same size and memory alignment.

Declaration
public static bool AreCompatible<T1, T2>() where T1 : allows ref struct where T2 : allows ref struct
Returns
Type Description
bool

true if both types are binary compatible; otherwise, false.

Type Parameters
Name Description
T1

The first type to compare.

T2

The second type to compare.

View Source

AsRef<T>(TypedReference)

Converts typed reference into managed pointer.

Declaration
[CLSCompliant(false)]
public static ref T AsRef<T>(this TypedReference reference) where T : allows ref struct
Parameters
Type Name Description
TypedReference reference

The typed reference.

Returns
Type Description
T

A managed pointer to the value represented by reference.

Type Parameters
Name Description
T

The type of the value.

Exceptions
Type Condition
InvalidCastException

T is not identical to the type stored in the typed reference.

View Source

Cast<T>(object?)

Provides unified behavior of type cast for reference and value types.

Declaration
public static T Cast<T>(object? obj)
Parameters
Type Name Description
object obj

The object to cast.

Returns
Type Description
T

The result of conversion.

Type Parameters
Name Description
T
Remarks

This method never returns null because it treats null value passed to obj as invalid object of type T.

Exceptions
Type Condition
InvalidCastException

obj is null or not of type T.

View Source

Copy<T>(in T, out T)

Copies one value into another.

Declaration
public static void Copy<T>(in T input, out T output) where T : struct, allows ref struct
Parameters
Type Name Description
T input

The reference to the source location.

T output

The reference to the destination location.

Type Parameters
Name Description
T

The value type to copy.

View Source

Copy<T>(in T, out T, nuint)

Copies the specified number of elements from source address to the destination address.

Declaration
[CLSCompliant(false)]
public static void Copy<T>(in T source, out T destination, nuint count) where T : unmanaged, allows ref struct
Parameters
Type Name Description
T source

The address of the bytes to copy.

T destination

The target address.

nuint count

The number of elements to copy.

Type Parameters
Name Description
T

The type of the element.

View Source

HasFinalizer(object)

Determines whether the object overrides ~Object() method.

Declaration
public static bool HasFinalizer(object obj)
Parameters
Type Name Description
object obj

The object to check.

Returns
Type Description
bool

true if ~Object() is overridden; otherwise, false.

View Source

IsDefault<T>(in T)

Indicates that specified value type is the default value.

Declaration
public static bool IsDefault<T>(in T value) where T : allows ref struct
Parameters
Type Name Description
T value

Value to check.

Returns
Type Description
bool

true, if value is default value; otherwise, false.

Type Parameters
Name Description
T

The type of the value to check.

View Source

IsNaturallyAligned<T>()

Indicates that a value of type T can aligned to nuint size safely.

Declaration
public static bool IsNaturallyAligned<T>() where T : allows ref struct
Returns
Type Description
bool

true if T can be aligned to nuint size; otherwise, false.

Type Parameters
Name Description
T

The type to check.

View Source

IsNullable<T>()

Provides the fast way to check whether the specified type accepts null value as valid value.

Declaration
public static bool IsNullable<T>()
Returns
Type Description
bool

true if T is nullable type; otherwise, false.

Type Parameters
Name Description
T

The type to check.

Remarks

This method always returns true for all reference types and Nullable<T>. On mainstream implementations of .NET CLR, this method is replaced by constant value by JIT compiler with zero runtime overhead.

View Source

Swap<T>(ref T, ref T)

Swaps two values.

Declaration
public static void Swap<T>(ref T first, ref T second) where T : allows ref struct
Parameters
Type Name Description
T first

The first value to be replaced with second.

T second

The second value to be replaced with first.

Type Parameters
Name Description
T

The type of the value.

View Source

get_Alignment<T>()

Gets the alignment of the type, in bytes.

Declaration
public static int get_Alignment<T>() where T : allows ref struct
Returns
Type Description
int
Type Parameters
Name Description
T
View Source

get_TypeId<T>()

Gets the type handle.

Declaration
public static RuntimeTypeHandle get_TypeId<T>() where T : allows ref struct
Returns
Type Description
RuntimeTypeHandle
Type Parameters
Name Description
T
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾