Show / Hide Table of Contents

Class Intrinsics

Represents highly optimized runtime intrinsic methods.

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

Methods

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

| Edit this page View Source

AlignOf<T>()

Gets the alignment requirement for type T, in bytes.

Declaration
public static int AlignOf<T>()
Returns
Type Description
int

The alignment of the type T.

Type Parameters
Name Description
T

The target type.

See Also
_Alignof operator in C++
| Edit this page 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>()
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.

| Edit this page View Source

AsRef<T>(TypedReference)

Converts typed reference into managed pointer.

Declaration
[CLSCompliant(false)]
public static ref T AsRef<T>(this TypedReference reference)
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.

| Edit this page View Source

Cast<T>(object?)

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

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

The object to cast.

Returns
Type Description
T

The result of conversion.

Type Parameters
Name Description
T

Conversion result.

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.

| Edit this page View Source

Compare(void*, void*, nuint)

Bitwise comparison of two memory blocks.

Declaration
[CLSCompliant(false)]
public static int Compare(void* first, void* second, nuint length)
Parameters
Type Name Description
void* first

The pointer to the first memory block.

void* second

The pointer to the second memory block.

nuint length

The length of the first and second memory blocks.

Returns
Type Description
int

Comparison result which has the semantics as return type of CompareTo(object).

| Edit this page View Source

CopyUnaligned<T>(T*, T*)

Copies one value into another assuming unaligned memory access.

Declaration
[CLSCompliant(false)]
public static void CopyUnaligned<T>(T* input, T* output) where T : unmanaged
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.

| Edit this page View Source

Copy<T>(T*, T*)

Copies one value into another.

Declaration
[CLSCompliant(false)]
public static void Copy<T>(T* input, T* output) where T : unmanaged
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.

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

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

| Edit this page View Source

Equals(void*, void*, nuint)

Computes equality between two blocks of memory.

Declaration
[CLSCompliant(false)]
public static bool Equals(void* first, void* second, nuint length)
Parameters
Type Name Description
void* first

A pointer to the first memory block.

void* second

A pointer to the second memory block.

nuint length

Length of first and second memory blocks, in bytes.

Returns
Type Description
bool

true, if both memory blocks have the same data; otherwise, false.

| Edit this page View Source

GetLength(Array)

Gets length of the array.

Declaration
[CLSCompliant(false)]
public static nuint GetLength(this Array array)
Parameters
Type Name Description
Array array

The array object.

Returns
Type Description
nuint

The length of the array as native unsigned integer.

Remarks

This method supports one-dimensional as well as multidimensional arrays.

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

| Edit this page View Source

IsDefault<T>(in T)

Indicates that specified value type is the default value.

Declaration
public static bool IsDefault<T>(in T value)
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.

| Edit this page View Source

IsExactTypeOf<T>(object?)

Checks whether the specified object is exactly of the specified type.

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

The object to test.

Returns
Type Description
bool

true if obj is not null and of type T; otherwise, false.

Type Parameters
Name Description
T

The expected type of object.

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

| Edit this page View Source

KeepAlive<T>(ref readonly T)

Keeps the reference to the value type alive.

Declaration
public static void KeepAlive<T>(ref readonly T location) where T : struct
Parameters
Type Name Description
T location

A location of the object.

Type Parameters
Name Description
T

The value type.

| Edit this page View Source

PointerHashCode(void*)

Computes transient hash code of the specified pointer.

Declaration
[CLSCompliant(false)]
public static int PointerHashCode(void* pointer)
Parameters
Type Name Description
void* pointer

The pointer value.

Returns
Type Description
int

The hash code of the pointer.

| Edit this page View Source

Swap<T>(T*, T*)

Swaps two values.

Declaration
[CLSCompliant(false)]
public static void Swap<T>(T* first, T* second) where T : unmanaged
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.

| Edit this page View Source

Swap<T>(ref T, ref T)

Swaps two values.

Declaration
public static void Swap<T>(ref T first, ref T second)
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.

| Edit this page View Source

TypeOf<T>()

Returns the runtime handle associated with type T.

Declaration
public static RuntimeTypeHandle TypeOf<T>()
Returns
Type Description
RuntimeTypeHandle

The runtime handle representing type T.

Type Parameters
Name Description
T

The type which runtime handle should be obtained.

  • Edit this page
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾