Class Intrinsics
Represents highly optimized runtime intrinsic methods.
Inherited Members
Namespace: DotNext.Runtime
Assembly: DotNext.dll
Syntax
public static class Intrinsics
Methods
| Edit this page View SourceAddressOf<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. |
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 |
Type Parameters
Name | Description |
---|---|
T | The target type. |
See Also
| Edit this page View SourceAreCompatible<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 |
Type Parameters
Name | Description |
---|---|
T1 | The first type to compare. |
T2 | The second type to compare. |
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 |
|
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 |
|
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). |
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. |
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. |
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. |
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. |
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. |
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 multi-dimensional arrays.
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 |
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 |
Type Parameters
Name | Description |
---|---|
T | The type of the value to check. |
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 |
Type Parameters
Name | Description |
---|---|
T | The expected type of object. |
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 |
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.
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. |
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 |
T* | second | The second value to be replaced with |
Type Parameters
Name | Description |
---|---|
T | The type of the value. |
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 |
T | second | The second value to be replaced with |
Type Parameters
Name | Description |
---|---|
T | The type of the value. |
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 |
Type Parameters
Name | Description |
---|---|
T | The type which runtime handle should be obtained. |