Table of Contents

Class Extensions

Namespace
MonoMod.Utils
Assembly
MonoMod.Utils.dll
Collection of extensions used by MonoMod and other projects.
public static class Extensions
Inheritance
Extensions

Methods

AddRange(IDictionary, IDictionary)
See AddRange(IEnumerable<T>)
AddRange<T>(Collection<T>, IEnumerable<T>)
See AddRange(IEnumerable<T>)
AddRange<TKey, TValue>(Dictionary<TKey, TValue>, Dictionary<TKey, TValue>)
See AddRange(IEnumerable<T>)
AddRange<TKey, TValue>(IDictionary<TKey, TValue>, IDictionary<TKey, TValue>)
See AddRange(IEnumerable<T>)
CastDelegate(Delegate?, Type)
Cast a delegate from one type to another. Compatible with delegates holding an invocation list (combined delegates).
CastDelegate<T>(Delegate)
Cast a delegate from one type to another. Compatible with delegates holding an invocation list (combined delegates).
Clone(MethodBody?, MethodDefinition)
Clone the given method body.
Clone(CustomAttribute)
Clone the given custom attribute.
Clone(GenericParameter)
Clone the given generic parameter.
Clone(MethodDefinition?, MethodDefinition?)
Clone the given method definition.
Clone(ParameterDefinition)
Clone the given parameter definition.
Create(ILProcessor, OpCode, object)
Create(ILProcessor, OpCode, FieldInfo)
Create(ILProcessor, OpCode, MemberInfo)
Create(ILProcessor, OpCode, MethodBase)
Create(ILProcessor, OpCode, Type)
CreateDelegate(MethodBase, Type)
Creates a delegate of the specified type from this method.
CreateDelegate(MethodBase, Type, object?)
Creates a delegate of the specified type with the specified target from this method.
CreateDelegate<T>(MethodBase)
Creates a delegate of the specified type from this method.
CreateDelegate<T>(MethodBase, object?)
Creates a delegate of the specified type with the specified target from this method.
Emit(ILProcessor, OpCode, object)
Emit(ILProcessor, OpCode, FieldInfo)
Emit(ILProcessor, OpCode, MemberInfo)
Emit(ILProcessor, OpCode, MethodBase)
Emit(ILProcessor, OpCode, Type)
FindEvent(TypeDefinition, string)
Find an event for a given name.
FindEventDeep(TypeDefinition, string)
Find an event for a given name recursively (including the passed type's base types).
FindField(TypeDefinition, string)
Find a field for a given name.
FindFieldDeep(TypeDefinition, string)
Find a field for a given name recursively (including the passed type's base types).
FindMethod(TypeDefinition, string, bool)
Find a method for a given ID.
FindMethod(Type, string, bool)
Find a method for a given ID.
FindMethodDeep(TypeDefinition, string, bool)
Find a method for a given ID recursively (including the passed type's base types).
FindMethodDeep(Type, string, bool)
Find a method for a given ID recursively (including the passed type's base types).
FindProperty(TypeDefinition, string)
Find a property for a given name.
FindPropertyDeep(TypeDefinition, string)
Find a property for a given name recursively (including the passed type's base types).
FixShortLongOps(MethodDefinition)
Fix (and optimize) any instructions which should use the long / short form opcodes instead.
GetActualGenericMethodDefinition(MethodInfo)
Gets the actual generic method definition of a method, as defined on the fully open type.
GetCustomAttribute(ICustomAttributeProvider, string)
Get a certain custom attribute from an attribute provider.
GetDeclaredMember<T>(T)
GetID(CallSite)
Get a reference ID that is similar to the full name, but consistent between System.Reflection and Mono.Cecil.
GetID(MethodReference, string?, string?, bool, bool)
Get a reference ID that is similar to the full name, but consistent between System.Reflection and Mono.Cecil.
GetID(MethodBase, string?, string?, bool, bool, bool)
Get a reference ID that is similar to the full name, but consistent between System.Reflection and Mono.Cecil.
GetInt(Instruction)
Get the integer value pushed onto the stack with this instruction.
GetIntOrNull(Instruction)
Get the integer value pushed onto the stack with this instruction.
GetLdftnPointer(MethodBase)
Get a native function pointer for a given method. This matches an IL-level ldftn.
GetManagedSize(Type)
Get the managed size of a given type. This matches an IL-level sizeof(t), even if it cannot be determined normally in C#. Note that sizeof(t) != Marshal.SizeOf(t), f.e. when t is char.
GetPatchFullName(MemberReference)
Get the "patch name" - the name of the target to patch - for the given member.
GetPatchName(MemberReference)
Get the "patch name" - the name of the target to patch - for the given member.
GetStateMachineTarget(MethodInfo)
Get the method of interest for a given state machine method.
GetThisParamType(MethodBase)
Get a type which matches what the method should receive via ldarg.0
GetUnfilledMethodOnGenericType(MethodBase)
HasCustomAttribute(ICustomAttributeProvider, string)
Determine if an attribute provider has got a specific custom attribute.
Import(ILProcessor, FieldInfo)
Import(ILProcessor, MemberInfo)
Import(ILProcessor, MethodBase)
Import(ILProcessor, Type)
ImportReference(ModuleDefinition, CallSite)
ImportReference(ModuleDefinition, IMetadataTokenProvider)
InsertRange<T>(Collection<T>, int, IEnumerable<T>)
See InsertRange(int, IEnumerable<T>)
InvokePassing<T>(MulticastDelegate, T, params object?[])
Invokes all delegates in the invocation list, passing on the result to the next.
InvokeWhileFalse(MulticastDelegate, params object[])
Invokes all delegates in the invocation list, as long as the previously invoked delegate returns false.
InvokeWhileNull<T>(MulticastDelegate?, params object[])
Invokes all delegates in the invocation list, as long as the previously invoked delegate returns null.
InvokeWhileTrue(MulticastDelegate, params object[])
Invokes all delegates in the invocation list, as long as the previously invoked delegate returns true.
Is(MemberReference?, MemberInfo?)
Check if the signatures of a given System.Reflection and Mono.Cecil member reference match.
Is(MemberReference, string)
Is(MemberReference, string, string)
Is(MemberReference, Type, string)
Is(MethodReference, string)
Is(MethodReference, string, string)
Is(MethodReference, Type, string)
Is(MemberInfo?, MemberReference?)
Check if the signatures of a given System.Reflection and Mono.Cecil member reference match.
IsBaseMethodCall(MethodBody, MethodReference?)
Determine if the method call is a base method call.
IsCallvirt(MethodReference)
Determine if the given method can be preferably called using callvirt.
IsCompatible(Type, Type)
Determine if two types are compatible with each other (f.e. object with string, or enums with their underlying integer type).
IsDynamicMethod(MethodBase)
IsStruct(TypeReference)
Determine if the given type is a struct (also known as "value type") or struct-alike (f.e. primitive).
ReadNullTerminatedString(BinaryReader)
Read the string from the BinaryReader BinaryWriter in a C-friendly format.
RecalculateILOffsets(MethodDefinition)
Calculate updated instruction offsets. Required for certain manual fixes.
Relink(CallSite, Relinker, IGenericParameterProvider)
Relink the given callsite.
Relink(CustomAttribute, Relinker, IGenericParameterProvider)
Relink the given custom attribute.
Relink(FieldReference, Relinker, IGenericParameterProvider)
Relink the given field reference.
Relink(GenericParameter, Relinker, IGenericParameterProvider)
Relink the given generic parameter reference.
Relink(GenericParameterConstraint?, Relinker, IGenericParameterProvider)
Relink the given type reference.
Relink(IMetadataTokenProvider?, Relinker, IGenericParameterProvider)
Relink the given member reference (metadata token provider).
Relink(MethodReference, Relinker, IGenericParameterProvider)
Relink the given method reference.
Relink(ParameterDefinition, Relinker, IGenericParameterProvider)
Relink the given parameter definition.
Relink(TypeReference?, Relinker, IGenericParameterProvider?)
Relink the given type reference.
ReplaceOperands(ILProcessor, object?, object?)
ResolveGenericParameter(IGenericParameterProvider, GenericParameter)
Resolve a given generic parameter in another context.
SafeGetIsAlive(WeakReference)
SafeGetTarget(WeakReference)
SafeResolve(FieldReference?)
Safely resolve a reference, silently discarding any exceptions.
SafeResolve(MethodReference?)
Safely resolve a reference, silently discarding any exceptions.
SafeResolve(PropertyReference?)
Safely resolve a reference, silently discarding any exceptions.
SafeResolve(TypeReference?)
Safely resolve a reference, silently discarding any exceptions.
SetMonoCorlibInternal(Assembly, bool)
SpacedPascalCase(string)
Split PascalCase words to become Pascal Case instead.
ToHexadecimalString(byte[])
Create a hexadecimal string for the given bytes.
ToLongOp(OpCode)
Get the long form opcode for any short form opcode.
ToShortOp(OpCode)
Get the short form opcode for any long form opcode.
TryCastDelegate(Delegate, Type, out Delegate?)
TryCastDelegate<T>(Delegate, out T)
TryCreateDelegate<T>(MethodInfo?)
Update(GenericParameter, int, GenericParameterType)
Force-update a generic parameter's position and type.
WriteNullTerminatedString(BinaryWriter, string)
Write the string to the BinaryWriter in a C-friendly format.