Early Preview
This is currently very much a preview. Please feel free to try things out,
but don't be upset if anything is not yet working. Feedback is welcome over on our
GitHub Dicussions page.
class System.​Runtime.​CompilerServices.​RuntimeHelpers
Assembly: System.Runtime
Inheritance: object → RuntimeHelpers
Provides a set of static methods and properties that provide support for compilers. This class cannot be inherited.
Properties
public static
int
OffsetToStringData
Gets the offset, in bytes, to the data in the given string.
Methods
public static
nint
AllocateTypeAssociatedMemory​(Type type,
int size)
Allocates memory that's associated with the <paramref name="type" /> and is freed if and when the <see cref="T:System.Type" /> is unloaded.
Returns The allocated memory.
type
The type associated with the allocated memory.
size
The amount of memory to allocate, in bytes.
public static
ReadOnlySpan<​T>
CreateSpan​(RuntimeFieldHandle fldHandle)
Provides a fast way to access constant data stored in a module as a <see cref="T:System.ReadOnlySpan`1" /> .
Returns The data stored in the field.
fldHandle
A field handle that specifies the location of the data to be referred to by the <see cref="T:System.ReadOnlySpan`1" /> . The Rva of the field must be aligned on a natural boundary of <typeparamref name="T" /> .
public static
void
EnsureSufficientExecutionStack​()
Ensures that the remaining stack space is large enough to execute the average .NET function.
public static
bool
Equals​(object o1,
object o2)
Determines whether the specified <see cref="T:System.Object" /> instances are considered equal.
Returns <see langword="true" /> if <paramref name="o1" /> is the same instance as <paramref name="o2" /> , or if both are <see langword="null" /> , or if both are the same value type and the values of their underlying memory are equal; otherwise, <see langword="false" /> .
o1
The first object to compare.
o2
The second object to compare.
public static
void
ExecuteCodeWithGuaranteedCleanup​(TryCode code,
CleanupCode backoutCode,
object userData)
public static
int
GetHashCode​(object o)
Serves as a hash function for a particular object, and is suitable for use in algorithms and data structures that use hash codes, such as a hash table.
Returns A hash code for the object identified by the <paramref name="o" /> parameter.
o
An object to retrieve the hash code for.
public static
object
GetObjectValue​(object obj)
Boxes a value type.
Returns A boxed copy of <paramref name="obj" /> if it is a value class; otherwise, <paramref name="obj" /> itself.
obj
The value type to be boxed.
public static
T[]
GetSubArray​(T[] array,
Range range)
Slices the specified array using the specified range.
Returns The subarray defined by <paramref name="range" /> .
array
The array to slice.
range
An object that determines the portion of <paramref name="array" /> to include in the slice.
public static
object
GetUninitializedObject​(Type type)
Returns an uninitialized instance of the system-provided type.
Returns An object representing the uninitialized system-provided type instance.
type
A system-provided type.
public static
void
InitializeArray​(Array array,
RuntimeFieldHandle fldHandle)
Provides a fast way to initialize an array from data that is stored in a module.
array
The array to be initialized.
fldHandle
A field handle that specifies the location of the data used to initialize the array.
public static
bool
IsReferenceOrContainsReferences​()
Returns a value that indicates whether the specified type is a reference type or a value type that contains references or by-refs.
Returns <see langword="true" /> if the given type is a reference type or a value type that contains references or by-refs; otherwise, <see langword="false" /> .
public static
void
PrepareConstrainedRegions​()
Designates a body of code as a constrained execution region (CER).
public static
void
PrepareConstrainedRegionsNoOP​()
Designates a body of code as a constrained execution region (CER) without performing any probing.
public static
void
PrepareContractedDelegate​(delegate d)
Provides a way for applications to dynamically prepare <see cref="T:System.AppDomain" /> event delegates.
d
The event delegate to prepare.
public static
void
PrepareDelegate​(delegate d)
Indicates that the specified delegate should be prepared for inclusion in a constrained execution region (CER).
d
The delegate type to prepare.
public static
void
PrepareMethod​(RuntimeMethodHandle method)
Prepares a method for inclusion in a constrained execution region (CER).
method
A handle to the method to prepare.
public static
void
PrepareMethod​(RuntimeMethodHandle method,
RuntimeTypeHandle[] instantiation)
Prepares a method for inclusion in a constrained execution region (CER) with the specified instantiation.
method
A handle to the method to prepare.
instantiation
The instantiation to pass to the method.
public static
void
ProbeForSufficientStack​()
Probes for a certain amount of stack space to ensure that a stack overflow cannot happen within a subsequent block of code (assuming that your code uses only a finite and moderate amount of stack space). We recommend that you use a constrained execution region (CER) instead of this method.
public static
void
RunClassConstructor​(RuntimeTypeHandle type)
Ensures that the type initializer (also known as a static constructor) for the specified type has been run.
type
A type handle that specifies the type for which a type initializer should be run.
public static
void
RunModuleConstructor​(ModuleHandle module)
Ensures a specified module constructor method has run by the time this method returns.
module
A handle that specifies the module constructor method to run.
public static
int
SizeOf​(RuntimeTypeHandle type)
Gets the size of an object of the given type.
Returns The size of instances of the type.
type
The type to get the size of.
public static
bool
TryEnsureSufficientExecutionStack​()
Tries to ensure there is sufficient stack to execute the average .NET function.
Returns <see langword="true" /> if sufficient stack is present; otherwise, <see langword="false" /> .
public
bool
Equals​(object obj)
Inherited from object
Determines whether the specified object is equal to the current object.
Returns <see langword="true" /> if the specified object is equal to the current object; otherwise, <see langword="false" /> .
obj
The object to compare with the current object.
protected
void
Finalize​()
Inherited from object
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
public
int
GetHashCode​()
Inherited from object
Serves as the default hash function.
Returns A hash code for the current object.
public
Type
GetType​()
Inherited from object
Gets the <see cref="T:System.Type" /> of the current instance.
Returns The exact runtime type of the current instance.
protected
object
MemberwiseClone​()
Inherited from object
Creates a shallow copy of the current <see cref="T:System.Object" /> .
Returns A shallow copy of the current <see cref="T:System.Object" /> .
public
string
ToString​()
Inherited from object
Returns a string that represents the current object.
Returns A string that represents the current object.