Class AdvancedHelpers
Represents advanced helpers.
Inherited Members
Namespace: DotNext.Runtime.CompilerServices
Assembly: DotNext.dll
Syntax
public static class AdvancedHelpers
Methods
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) 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. |
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 |
Type Parameters
| Name | Description |
|---|---|
| T | The target type. |
See Also
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>() where T1 : allows ref struct where T2 : allows ref struct
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) 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 |
|
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 |
|
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. |
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. |
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) where T : allows ref struct
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. |
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 |
Type Parameters
| Name | Description |
|---|---|
| T | The type to check. |
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.
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 |
| T | second | The second value to be replaced with |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the value. |
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 |
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 |