Class Extensions
Collection of extensions used by MonoMod and other projects.
Inheritance
Namespace: MonoMod.Utils
Assembly: MonoMod.Utils.dll
Syntax
public static class Extensions : Object
Methods
AddRange(IDictionary, IDictionary)
See System.Collections.Generic.List`1.AddRange(System.Collections.Generic.IEnumerable{`0})
Declaration
public static void AddRange(this IDictionary dict, IDictionary other)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.IDictionary | dict | |
System.Collections.IDictionary | other |
AddRange<T>(Collection<T>, IEnumerable<T>)
See System.Collections.Generic.List`1.AddRange(System.Collections.Generic.IEnumerable{`0})
Declaration
public static void AddRange<T>(this Collection<T> list, IEnumerable<T> other)
Parameters
Type | Name | Description |
---|---|---|
Mono.Collections.Generic.Collection<T> | list | |
System.Collections.Generic.IEnumerable<T> | other |
Type Parameters
Name | Description |
---|---|
T |
AddRange<K, V>(Dictionary<K, V>, Dictionary<K, V>)
See System.Collections.Generic.List`1.AddRange(System.Collections.Generic.IEnumerable{`0})
Declaration
public static void AddRange<K, V>(this Dictionary<K, V> dict, Dictionary<K, V> other)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.Dictionary<K, V> | dict | |
System.Collections.Generic.Dictionary<K, V> | other |
Type Parameters
Name | Description |
---|---|
K | |
V |
AddRange<K, V>(IDictionary<K, V>, IDictionary<K, V>)
See System.Collections.Generic.List`1.AddRange(System.Collections.Generic.IEnumerable{`0})
Declaration
public static void AddRange<K, V>(this IDictionary<K, V> dict, IDictionary<K, V> other)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IDictionary<K, V> | dict | |
System.Collections.Generic.IDictionary<K, V> | other |
Type Parameters
Name | Description |
---|---|
K | |
V |
CastDelegate(Delegate, Type)
Cast a delegate from one type to another. Compatible with delegates holding an invocation list (combined delegates).
Declaration
public static Delegate CastDelegate(this Delegate source, Type type)
Parameters
Type | Name | Description |
---|---|---|
System.Delegate | source | The input delegate. |
System.Type | type | The wanted output delegate type. |
Returns
Type | Description |
---|---|
System.Delegate | The output delegate. |
CastDelegate<T>(Delegate)
Cast a delegate from one type to another. Compatible with delegates holding an invocation list (combined delegates).
Declaration
public static T CastDelegate<T>(this Delegate source)
where T : class
Parameters
Type | Name | Description |
---|---|---|
System.Delegate | source | The input delegate. |
Returns
Type | Description |
---|---|
T | The output delegate. |
Type Parameters
Name | Description |
---|---|
T |
Clone(MethodBody, MethodDefinition)
Clone the given method body.
Declaration
public static MethodBody Clone(this MethodBody bo, MethodDefinition m)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.Cil.MethodBody | bo | The original method body. |
Mono.Cecil.MethodDefinition | m | The method which will own the newly cloned method body. |
Returns
Type | Description |
---|---|
Mono.Cecil.Cil.MethodBody | A clone of the original method body. |
Clone(CustomAttribute)
Clone the given custom attribute.
Declaration
public static CustomAttribute Clone(this CustomAttribute attrib)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.CustomAttribute | attrib | The original custom attribute. |
Returns
Type | Description |
---|---|
Mono.Cecil.CustomAttribute | A clone of the original custom attribute. |
Clone(GenericParameter)
Clone the given generic parameter.
Declaration
public static GenericParameter Clone(this GenericParameter param)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.GenericParameter | param | The original generic parameter. |
Returns
Type | Description |
---|---|
Mono.Cecil.GenericParameter | A clone of the original generic parameter. |
Clone(MethodDefinition, MethodDefinition)
Clone the given method definition.
Declaration
public static MethodDefinition Clone(this MethodDefinition o, MethodDefinition c = null)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.MethodDefinition | o | The original method. |
Mono.Cecil.MethodDefinition | c | The method definition to apply the cloning process onto, or null to create a new method. |
Returns
Type | Description |
---|---|
Mono.Cecil.MethodDefinition | A clone of the original method. |
Clone(ParameterDefinition)
Clone the given parameter definition.
Declaration
public static ParameterDefinition Clone(this ParameterDefinition param)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.ParameterDefinition | param | The original parameter definition. |
Returns
Type | Description |
---|---|
Mono.Cecil.ParameterDefinition | A clone of the original parameter definition. |
Create(ILProcessor, OpCode, Object)
Declaration
public static Instruction Create(this ILProcessor il, OpCode opcode, object operand)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.Cil.ILProcessor | il | |
Mono.Cecil.Cil.OpCode | opcode | |
System.Object | operand |
Returns
Type | Description |
---|---|
Mono.Cecil.Cil.Instruction |
Create(ILProcessor, OpCode, FieldInfo)
Declaration
public static Instruction Create(this ILProcessor il, OpCode opcode, FieldInfo field)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.Cil.ILProcessor | il | |
Mono.Cecil.Cil.OpCode | opcode | |
System.Reflection.FieldInfo | field |
Returns
Type | Description |
---|---|
Mono.Cecil.Cil.Instruction |
Create(ILProcessor, OpCode, MemberInfo)
Declaration
public static Instruction Create(this ILProcessor il, OpCode opcode, MemberInfo member)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.Cil.ILProcessor | il | |
Mono.Cecil.Cil.OpCode | opcode | |
System.Reflection.MemberInfo | member |
Returns
Type | Description |
---|---|
Mono.Cecil.Cil.Instruction |
Create(ILProcessor, OpCode, MethodBase)
Declaration
public static Instruction Create(this ILProcessor il, OpCode opcode, MethodBase method)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.Cil.ILProcessor | il | |
Mono.Cecil.Cil.OpCode | opcode | |
System.Reflection.MethodBase | method |
Returns
Type | Description |
---|---|
Mono.Cecil.Cil.Instruction |
Create(ILProcessor, OpCode, Type)
Declaration
public static Instruction Create(this ILProcessor il, OpCode opcode, Type type)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.Cil.ILProcessor | il | |
Mono.Cecil.Cil.OpCode | opcode | |
System.Type | type |
Returns
Type | Description |
---|---|
Mono.Cecil.Cil.Instruction |
CreateDelegate(MethodBase, Type)
Creates a delegate of the specified type from this method.
Declaration
public static Delegate CreateDelegate(this MethodBase method, Type delegateType)
Parameters
Type | Name | Description |
---|---|---|
System.Reflection.MethodBase | method | The method to create the delegate from. |
System.Type | delegateType | The type of the delegate to create. |
Returns
Type | Description |
---|---|
System.Delegate | The delegate for this method. |
CreateDelegate(MethodBase, Type, Object)
Creates a delegate of the specified type with the specified target from this method.
Declaration
public static Delegate CreateDelegate(this MethodBase method, Type delegateType, object target)
Parameters
Type | Name | Description |
---|---|---|
System.Reflection.MethodBase | method | The method to create the delegate from. |
System.Type | delegateType | The type of the delegate to create. |
System.Object | target | The object targeted by the delegate. |
Returns
Type | Description |
---|---|
System.Delegate | The delegate for this method. |
CreateDelegate<T>(MethodBase)
Creates a delegate of the specified type from this method.
Declaration
public static Delegate CreateDelegate<T>(this MethodBase method)
where T : class
Parameters
Type | Name | Description |
---|---|---|
System.Reflection.MethodBase | method | The method to create the delegate from. |
Returns
Type | Description |
---|---|
System.Delegate | The delegate for this method. |
Type Parameters
Name | Description |
---|---|
T | The type of the delegate to create. |
CreateDelegate<T>(MethodBase, Object)
Creates a delegate of the specified type with the specified target from this method.
Declaration
public static Delegate CreateDelegate<T>(this MethodBase method, object target)
where T : class
Parameters
Type | Name | Description |
---|---|---|
System.Reflection.MethodBase | method | The method to create the delegate from. |
System.Object | target | The object targeted by the delegate. |
Returns
Type | Description |
---|---|
System.Delegate | The delegate for this method. |
Type Parameters
Name | Description |
---|---|
T | The type of the delegate to create. |
Emit(ILProcessor, OpCode, Object)
Declaration
public static void Emit(this ILProcessor il, OpCode opcode, object operand)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.Cil.ILProcessor | il | |
Mono.Cecil.Cil.OpCode | opcode | |
System.Object | operand |
Emit(ILProcessor, OpCode, FieldInfo)
Declaration
public static void Emit(this ILProcessor il, OpCode opcode, FieldInfo field)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.Cil.ILProcessor | il | |
Mono.Cecil.Cil.OpCode | opcode | |
System.Reflection.FieldInfo | field |
Emit(ILProcessor, OpCode, MemberInfo)
Declaration
public static void Emit(this ILProcessor il, OpCode opcode, MemberInfo member)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.Cil.ILProcessor | il | |
Mono.Cecil.Cil.OpCode | opcode | |
System.Reflection.MemberInfo | member |
Emit(ILProcessor, OpCode, MethodBase)
Declaration
public static void Emit(this ILProcessor il, OpCode opcode, MethodBase method)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.Cil.ILProcessor | il | |
Mono.Cecil.Cil.OpCode | opcode | |
System.Reflection.MethodBase | method |
Emit(ILProcessor, OpCode, Type)
Declaration
public static void Emit(this ILProcessor il, OpCode opcode, Type type)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.Cil.ILProcessor | il | |
Mono.Cecil.Cil.OpCode | opcode | |
System.Type | type |
FindEvent(TypeDefinition, String)
Find an event for a given name.
Declaration
public static EventDefinition FindEvent(this TypeDefinition type, string name)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.TypeDefinition | type | The type to search in. |
System.String | name | The event name. |
Returns
Type | Description |
---|---|
Mono.Cecil.EventDefinition | The first matching event or null. |
FindEventDeep(TypeDefinition, String)
Find an event for a given name recursively (including the passed type's base types).
Declaration
public static EventDefinition FindEventDeep(this TypeDefinition type, string name)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.TypeDefinition | type | The type to search in. |
System.String | name | The event name. |
Returns
Type | Description |
---|---|
Mono.Cecil.EventDefinition | The first matching event or null. |
FindField(TypeDefinition, String)
Find a field for a given name.
Declaration
public static FieldDefinition FindField(this TypeDefinition type, string name)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.TypeDefinition | type | The type to search in. |
System.String | name | The field name. |
Returns
Type | Description |
---|---|
Mono.Cecil.FieldDefinition | The first matching field or null. |
FindFieldDeep(TypeDefinition, String)
Find a field for a given name recursively (including the passed type's base types).
Declaration
public static FieldDefinition FindFieldDeep(this TypeDefinition type, string name)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.TypeDefinition | type | The type to search in. |
System.String | name | The field name. |
Returns
Type | Description |
---|---|
Mono.Cecil.FieldDefinition | The first matching field or null. |
FindMethod(TypeDefinition, String, Boolean)
Find a method for a given ID.
Declaration
public static MethodDefinition FindMethod(this TypeDefinition type, string id, bool simple = true)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.TypeDefinition | type | The type to search in. |
System.String | id | The method ID. |
System.Boolean | simple | Whether to perform a simple search pass as well or not. |
Returns
Type | Description |
---|---|
Mono.Cecil.MethodDefinition | The first matching method or null. |
FindMethod(Type, String, Boolean)
Find a method for a given ID.
Declaration
public static MethodInfo FindMethod(this Type type, string id, bool simple = true)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The type to search in. |
System.String | id | The method ID. |
System.Boolean | simple | Whether to perform a simple search pass as well or not. |
Returns
Type | Description |
---|---|
System.Reflection.MethodInfo | The first matching method or null. |
FindMethodDeep(TypeDefinition, String, Boolean)
Find a method for a given ID recursively (including the passed type's base types).
Declaration
public static MethodDefinition FindMethodDeep(this TypeDefinition type, string id, bool simple = true)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.TypeDefinition | type | The type to search in. |
System.String | id | The method ID. |
System.Boolean | simple | Whether to perform a simple search pass as well or not. |
Returns
Type | Description |
---|---|
Mono.Cecil.MethodDefinition | The first matching method or null. |
FindMethodDeep(Type, String, Boolean)
Find a method for a given ID recursively (including the passed type's base types).
Declaration
public static MethodInfo FindMethodDeep(this Type type, string id, bool simple = true)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The type to search in. |
System.String | id | The method ID. |
System.Boolean | simple | Whether to perform a simple search pass as well or not. |
Returns
Type | Description |
---|---|
System.Reflection.MethodInfo | The first matching method or null. |
FindProperty(TypeDefinition, String)
Find a property for a given name.
Declaration
public static PropertyDefinition FindProperty(this TypeDefinition type, string name)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.TypeDefinition | type | The type to search in. |
System.String | name | The property name. |
Returns
Type | Description |
---|---|
Mono.Cecil.PropertyDefinition | The first matching property or null. |
FindPropertyDeep(TypeDefinition, String)
Find a property for a given name recursively (including the passed type's base types).
Declaration
public static PropertyDefinition FindPropertyDeep(this TypeDefinition type, string name)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.TypeDefinition | type | The type to search in. |
System.String | name | The property name. |
Returns
Type | Description |
---|---|
Mono.Cecil.PropertyDefinition | The first matching property or null. |
FixShortLongOps(MethodDefinition)
Fix (and optimize) any instructions which should use the long / short form opcodes instead.
Declaration
public static void FixShortLongOps(this MethodDefinition method)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.MethodDefinition | method | The method to apply the fixes to. |
GetCustomAttribute(ICustomAttributeProvider, String)
Get a certain custom attribute from an attribute provider.
Declaration
public static CustomAttribute GetCustomAttribute(this ICustomAttributeProvider cap, string attribute)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.ICustomAttributeProvider | cap | The attribute provider. |
System.String | attribute | The custom attribute name. |
Returns
Type | Description |
---|---|
Mono.Cecil.CustomAttribute | The first matching custom attribute, or null if no matching attribute has been found. |
GetID(CallSite)
Get a reference ID that is similar to the full name, but consistent between System.Reflection and Mono.Cecil.
Declaration
public static string GetID(this CallSite method)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.CallSite | method | The call site to get the ID for. |
Returns
Type | Description |
---|---|
System.String | The ID. |
GetID(MethodReference, String, String, Boolean, Boolean)
Get a reference ID that is similar to the full name, but consistent between System.Reflection and Mono.Cecil.
Declaration
public static string GetID(this MethodReference method, string name = null, string type = null, bool withType = true, bool simple = false)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.MethodReference | method | The method to get the ID for. |
System.String | name | The name to use instead of the reference's own name. |
System.String | type | The ID to use instead of the reference's declaring type ID. |
System.Boolean | withType | Whether the type ID should be included or not. System.Reflection avoids it by default. |
System.Boolean | simple | Whether the ID should be "simple" (name only). |
Returns
Type | Description |
---|---|
System.String | The ID. |
GetID(MethodBase, String, String, Boolean, Boolean, Boolean)
Get a reference ID that is similar to the full name, but consistent between System.Reflection and Mono.Cecil.
Declaration
public static string GetID(this MethodBase method, string name = null, string type = null, bool withType = true, bool proxyMethod = false, bool simple = false)
Parameters
Type | Name | Description |
---|---|---|
System.Reflection.MethodBase | method | The method to get the ID for. |
System.String | name | The name to use instead of the reference's own name. |
System.String | type | The ID to use instead of the reference's declaring type ID. |
System.Boolean | withType | Whether the type ID should be included or not. System.Reflection avoids it by default. |
System.Boolean | proxyMethod | Whether the method is regarded as a proxy method or not. Setting this paramater to true will skip the first parameter. |
System.Boolean | simple | Whether the ID should be "simple" (name only). |
Returns
Type | Description |
---|---|
System.String | The ID. |
GetInt(Instruction)
Get the integer value pushed onto the stack with this instruction.
Declaration
public static int GetInt(this Instruction instr)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.Cil.Instruction | instr | The instruction to get the pushed integer value for. |
Returns
Type | Description |
---|---|
System.Int32 | The pushed integer value. |
GetIntOrNull(Instruction)
Get the integer value pushed onto the stack with this instruction.
Declaration
public static Nullable<int> GetIntOrNull(this Instruction instr)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.Cil.Instruction | instr | The instruction to get the pushed integer value for. |
Returns
Type | Description |
---|---|
System.Nullable<System.Int32> | The pushed integer value or null. |
GetLdftnPointer(MethodBase)
Get a native function pointer for a given method. This matches an IL-level ldftn.
Declaration
public static IntPtr GetLdftnPointer(this MethodBase m)
Parameters
Type | Name | Description |
---|---|---|
System.Reflection.MethodBase | m | The method to get a native function pointer for. |
Returns
Type | Description |
---|---|
System.IntPtr | The native function pointer. |
Remarks
ldftn doesn't JIT-compile the method on mono, which thus keeps the class constructor untouched. On the other hand, its result thus doesn't always match that of MethodHandle.GetFunctionPointer().
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.
Declaration
public static int GetManagedSize(this Type t)
Parameters
Type | Name | Description |
---|---|---|
System.Type | t | The type to get the size from. |
Returns
Type | Description |
---|---|
System.Int32 | The managed type size. |
GetPatchFullName(MemberReference)
Get the "patch name" - the name of the target to patch - for the given member.
Declaration
public static string GetPatchFullName(this MemberReference mr)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.MemberReference | mr | The member to get the patch name for. |
Returns
Type | Description |
---|---|
System.String | The patch name. |
GetPatchName(MemberReference)
Get the "patch name" - the name of the target to patch - for the given member.
Declaration
public static string GetPatchName(this MemberReference mr)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.MemberReference | mr | The member to get the patch name for. |
Returns
Type | Description |
---|---|
System.String | The patch name. |
GetThisParamType(MethodBase)
Get a type which matches what the method should receive via ldarg.0
Declaration
public static Type GetThisParamType(this MethodBase method)
Parameters
Type | Name | Description |
---|---|---|
System.Reflection.MethodBase | method | The method to obtain the "this" parameter type from. |
Returns
Type | Description |
---|---|
System.Type | The "this" parameter type. |
HasCustomAttribute(ICustomAttributeProvider, String)
Determine if an attribute provider has got a specific custom attribute.
Declaration
public static bool HasCustomAttribute(this ICustomAttributeProvider cap, string attribute)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.ICustomAttributeProvider | cap | The attribute provider. |
System.String | attribute | The custom attribute name. |
Returns
Type | Description |
---|---|
System.Boolean | true if the attribute provider contains the given custom attribute, false otherwise. |
Import(ILProcessor, FieldInfo)
Declaration
public static FieldReference Import(this ILProcessor il, FieldInfo field)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.Cil.ILProcessor | il | |
System.Reflection.FieldInfo | field |
Returns
Type | Description |
---|---|
Mono.Cecil.FieldReference |
Import(ILProcessor, MemberInfo)
Declaration
public static MemberReference Import(this ILProcessor il, MemberInfo member)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.Cil.ILProcessor | il | |
System.Reflection.MemberInfo | member |
Returns
Type | Description |
---|---|
Mono.Cecil.MemberReference |
Import(ILProcessor, MethodBase)
Declaration
public static MethodReference Import(this ILProcessor il, MethodBase method)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.Cil.ILProcessor | il | |
System.Reflection.MethodBase | method |
Returns
Type | Description |
---|---|
Mono.Cecil.MethodReference |
Import(ILProcessor, Type)
Declaration
public static TypeReference Import(this ILProcessor il, Type type)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.Cil.ILProcessor | il | |
System.Type | type |
Returns
Type | Description |
---|---|
Mono.Cecil.TypeReference |
ImportReference(ModuleDefinition, IMetadataTokenProvider)
Declaration
public static IMetadataTokenProvider ImportReference(this ModuleDefinition mod, IMetadataTokenProvider mtp)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.ModuleDefinition | mod | |
Mono.Cecil.IMetadataTokenProvider | mtp |
Returns
Type | Description |
---|---|
Mono.Cecil.IMetadataTokenProvider |
InsertRange<T>(Collection<T>, Int32, IEnumerable<T>)
See System.Collections.Generic.List`1.InsertRange(System.Int32,System.Collections.Generic.IEnumerable{`0})
Declaration
public static void InsertRange<T>(this Collection<T> list, int index, IEnumerable<T> other)
Parameters
Type | Name | Description |
---|---|---|
Mono.Collections.Generic.Collection<T> | list | |
System.Int32 | index | |
System.Collections.Generic.IEnumerable<T> | other |
Type Parameters
Name | Description |
---|---|
T |
InvokePassing<T>(MulticastDelegate, T, Object[])
Invokes all delegates in the invocation list, passing on the result to the next.
Declaration
public static T InvokePassing<T>(this MulticastDelegate md, T val, params object[] args)
Parameters
Type | Name | Description |
---|---|---|
System.MulticastDelegate | md | The multicast delegate. |
T | val | The initial value and first parameter. |
System.Object[] | args | Any other arguments that may be passed. |
Returns
Type | Description |
---|---|
T | The result of all delegates. |
Type Parameters
Name | Description |
---|---|
T | Type of the result. |
InvokeWhileFalse(MulticastDelegate, Object[])
Invokes all delegates in the invocation list, as long as the previously invoked delegate returns false.
Declaration
public static bool InvokeWhileFalse(this MulticastDelegate md, params object[] args)
Parameters
Type | Name | Description |
---|---|---|
System.MulticastDelegate | md | |
System.Object[] | args |
Returns
Type | Description |
---|---|
System.Boolean |
InvokeWhileNull<T>(MulticastDelegate, Object[])
Invokes all delegates in the invocation list, as long as the previously invoked delegate returns null.
Declaration
public static T InvokeWhileNull<T>(this MulticastDelegate md, params object[] args)
where T : class
Parameters
Type | Name | Description |
---|---|---|
System.MulticastDelegate | md | |
System.Object[] | args |
Returns
Type | Description |
---|---|
T |
Type Parameters
Name | Description |
---|---|
T |
InvokeWhileTrue(MulticastDelegate, Object[])
Invokes all delegates in the invocation list, as long as the previously invoked delegate returns true.
Declaration
public static bool InvokeWhileTrue(this MulticastDelegate md, params object[] args)
Parameters
Type | Name | Description |
---|---|---|
System.MulticastDelegate | md | |
System.Object[] | args |
Returns
Type | Description |
---|---|
System.Boolean |
Is(MemberReference, MemberInfo)
Check if the signatures of a given System.Reflection and Mono.Cecil member reference match.
Declaration
public static bool Is(this MemberReference mref, MemberInfo minfo)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.MemberReference | mref | The Mono.Cecil member reference. |
System.Reflection.MemberInfo | minfo | The System.Reflection member reference. |
Returns
Type | Description |
---|---|
System.Boolean | True if both references share the same signature, false otherwise. |
Is(MemberReference, String)
Declaration
public static bool Is(this MemberReference member, string fullName)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.MemberReference | member | |
System.String | fullName |
Returns
Type | Description |
---|---|
System.Boolean |
Is(MemberReference, String, String)
Declaration
public static bool Is(this MemberReference member, string typeFullName, string name)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.MemberReference | member | |
System.String | typeFullName | |
System.String | name |
Returns
Type | Description |
---|---|
System.Boolean |
Is(MemberReference, Type, String)
Declaration
public static bool Is(this MemberReference member, Type type, string name)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.MemberReference | member | |
System.Type | type | |
System.String | name |
Returns
Type | Description |
---|---|
System.Boolean |
Is(MemberInfo, MemberReference)
Check if the signatures of a given System.Reflection and Mono.Cecil member reference match.
Declaration
public static bool Is(this MemberInfo minfo, MemberReference mref)
Parameters
Type | Name | Description |
---|---|---|
System.Reflection.MemberInfo | minfo | The System.Reflection member reference. |
Mono.Cecil.MemberReference | mref | The Mono.Cecil member reference. |
Returns
Type | Description |
---|---|
System.Boolean | True if both references share the same signature, false otherwise. |
IsBaseMethodCall(MethodBody, MethodReference)
Determine if the method call is a base method call.
Declaration
public static bool IsBaseMethodCall(this MethodBody body, MethodReference called)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.Cil.MethodBody | body | The caller method body. |
Mono.Cecil.MethodReference | called | The called method. |
Returns
Type | Description |
---|---|
System.Boolean | True if the called method is a base method of the caller method, false otherwise. |
IsCallvirt(MethodReference)
Determine if the given method can be preferably called using callvirt.
Declaration
public static bool IsCallvirt(this MethodReference method)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.MethodReference | method | The called method. |
Returns
Type | Description |
---|---|
System.Boolean | True if the called method can be called using callvirt, false otherwise. |
IsCompatible(Type, Type)
Determine if two types are compatible with each other (f.e. object with string, or enums with their underlying integer type).
Declaration
public static bool IsCompatible(this Type type, Type other)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The first type. |
System.Type | other | The second type. |
Returns
Type | Description |
---|---|
System.Boolean | True if both types are compatible with each other, false otherwise. |
IsStruct(TypeReference)
Determine if the given type is a struct (also known as "value type") or struct-alike (f.e. primitive).
Declaration
public static bool IsStruct(this TypeReference type)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.TypeReference | type | The type to check. |
Returns
Type | Description |
---|---|
System.Boolean | True if the type is a struct, primitive or similar, false otherwise. |
LogDetailed(Exception, String)
Print the exception to the console, including extended loading / reflection data useful for mods.
Declaration
public static void LogDetailed(this Exception e, string tag = null)
Parameters
Type | Name | Description |
---|---|---|
System.Exception | e | |
System.String | tag |
ReadNullTerminatedString(BinaryReader)
Read the string from the BinaryReader BinaryWriter in a C-friendly format.
Declaration
public static string ReadNullTerminatedString(this BinaryReader stream)
Parameters
Type | Name | Description |
---|---|---|
System.IO.BinaryReader | stream | The input which the method reads from. |
Returns
Type | Description |
---|---|
System.String | The output string. |
RecalculateILOffsets(MethodDefinition)
Calculate updated instruction offsets. Required for certain manual fixes.
Declaration
public static void RecalculateILOffsets(this MethodDefinition method)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.MethodDefinition | method | The method to recalculate the IL instruction offsets for. |
Relink(CallSite, Relinker, IGenericParameterProvider)
Relink the given callsite.
Declaration
public static CallSite Relink(this CallSite method, Relinker relinker, IGenericParameterProvider context)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.CallSite | method | The reference to relink. |
Relinker | relinker | The relinker to use during the relinking process. |
Mono.Cecil.IGenericParameterProvider | context | The generic context provided to relink generic references. |
Returns
Type | Description |
---|---|
Mono.Cecil.CallSite | A relinked reference. |
Relink(CustomAttribute, Relinker, IGenericParameterProvider)
Relink the given custom attribute.
Declaration
public static CustomAttribute Relink(this CustomAttribute attrib, Relinker relinker, IGenericParameterProvider context)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.CustomAttribute | attrib | The reference to relink. |
Relinker | relinker | The relinker to use during the relinking process. |
Mono.Cecil.IGenericParameterProvider | context | The generic context provided to relink generic references. |
Returns
Type | Description |
---|---|
Mono.Cecil.CustomAttribute | A relinked reference. |
Relink(FieldReference, Relinker, IGenericParameterProvider)
Relink the given field reference.
Declaration
public static IMetadataTokenProvider Relink(this FieldReference field, Relinker relinker, IGenericParameterProvider context)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.FieldReference | field | The reference to relink. |
Relinker | relinker | The relinker to use during the relinking process. |
Mono.Cecil.IGenericParameterProvider | context | The generic context provided to relink generic references. |
Returns
Type | Description |
---|---|
Mono.Cecil.IMetadataTokenProvider | A relinked reference. |
Relink(GenericParameter, Relinker, IGenericParameterProvider)
Relink the given generic parameter reference.
Declaration
public static GenericParameter Relink(this GenericParameter param, Relinker relinker, IGenericParameterProvider context)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.GenericParameter | param | The reference to relink. |
Relinker | relinker | The relinker to use during the relinking process. |
Mono.Cecil.IGenericParameterProvider | context | The generic context provided to relink generic references. |
Returns
Type | Description |
---|---|
Mono.Cecil.GenericParameter | A relinked reference. |
Relink(GenericParameterConstraint, Relinker, IGenericParameterProvider)
Relink the given type reference.
Declaration
public static GenericParameterConstraint Relink(this GenericParameterConstraint constraint, Relinker relinker, IGenericParameterProvider context)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.GenericParameterConstraint | constraint | The reference to relink. |
Relinker | relinker | The relinker to use during the relinking process. |
Mono.Cecil.IGenericParameterProvider | context | The generic context provided to relink generic references. |
Returns
Type | Description |
---|---|
Mono.Cecil.GenericParameterConstraint | A relinked reference. |
Relink(IMetadataTokenProvider, Relinker, IGenericParameterProvider)
Relink the given member reference (metadata token provider).
Declaration
public static IMetadataTokenProvider Relink(this IMetadataTokenProvider mtp, Relinker relinker, IGenericParameterProvider context)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.IMetadataTokenProvider | mtp | The reference to relink. |
Relinker | relinker | The relinker to use during the relinking process. |
Mono.Cecil.IGenericParameterProvider | context | The generic context provided to relink generic references. |
Returns
Type | Description |
---|---|
Mono.Cecil.IMetadataTokenProvider | A relinked reference. |
Relink(MethodReference, Relinker, IGenericParameterProvider)
Relink the given method reference.
Declaration
public static IMetadataTokenProvider Relink(this MethodReference method, Relinker relinker, IGenericParameterProvider context)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.MethodReference | method | The reference to relink. |
Relinker | relinker | The relinker to use during the relinking process. |
Mono.Cecil.IGenericParameterProvider | context | The generic context provided to relink generic references. |
Returns
Type | Description |
---|---|
Mono.Cecil.IMetadataTokenProvider | A relinked reference. |
Relink(ParameterDefinition, Relinker, IGenericParameterProvider)
Relink the given parameter definition.
Declaration
public static ParameterDefinition Relink(this ParameterDefinition param, Relinker relinker, IGenericParameterProvider context)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.ParameterDefinition | param | The reference to relink. |
Relinker | relinker | The relinker to use during the relinking process. |
Mono.Cecil.IGenericParameterProvider | context | The generic context provided to relink generic references. |
Returns
Type | Description |
---|---|
Mono.Cecil.ParameterDefinition | A relinked reference. |
Relink(TypeReference, Relinker, IGenericParameterProvider)
Relink the given type reference.
Declaration
public static TypeReference Relink(this TypeReference type, Relinker relinker, IGenericParameterProvider context)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.TypeReference | type | The reference to relink. |
Relinker | relinker | The relinker to use during the relinking process. |
Mono.Cecil.IGenericParameterProvider | context | The generic context provided to relink generic references. |
Returns
Type | Description |
---|---|
Mono.Cecil.TypeReference | A relinked reference. |
ReplaceOperands(ILProcessor, Object, Object)
Declaration
public static void ReplaceOperands(this ILProcessor il, object from, object to)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.Cil.ILProcessor | il | |
System.Object | from | |
System.Object | to |
ResolveGenericParameter(IGenericParameterProvider, GenericParameter)
Resolve a given generic parameter in another context.
Declaration
public static GenericParameter ResolveGenericParameter(this IGenericParameterProvider provider, GenericParameter orig)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.IGenericParameterProvider | provider | The new context. |
Mono.Cecil.GenericParameter | orig | The original generic parameter. |
Returns
Type | Description |
---|---|
Mono.Cecil.GenericParameter | A generic parameter provided by the given context which matches the original generic parameter. |
SafeResolve(FieldReference)
Safely resolve a reference, silently discarding any exceptions.
Declaration
public static FieldDefinition SafeResolve(this FieldReference r)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.FieldReference | r | The reference to resolve. |
Returns
Type | Description |
---|---|
Mono.Cecil.FieldDefinition | The resolved definition or null. |
SafeResolve(MethodReference)
Safely resolve a reference, silently discarding any exceptions.
Declaration
public static MethodDefinition SafeResolve(this MethodReference r)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.MethodReference | r | The reference to resolve. |
Returns
Type | Description |
---|---|
Mono.Cecil.MethodDefinition | The resolved definition or null. |
SafeResolve(PropertyReference)
Safely resolve a reference, silently discarding any exceptions.
Declaration
public static PropertyDefinition SafeResolve(this PropertyReference r)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.PropertyReference | r | The reference to resolve. |
Returns
Type | Description |
---|---|
Mono.Cecil.PropertyDefinition | The resolved definition or null. |
SafeResolve(TypeReference)
Safely resolve a reference, silently discarding any exceptions.
Declaration
public static TypeDefinition SafeResolve(this TypeReference r)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.TypeReference | r | The reference to resolve. |
Returns
Type | Description |
---|---|
Mono.Cecil.TypeDefinition | The resolved definition or null. |
SpacedPascalCase(String)
Split PascalCase words to become Pascal Case instead.
Declaration
public static string SpacedPascalCase(this string input)
Parameters
Type | Name | Description |
---|---|---|
System.String | input | PascalCaseString |
Returns
Type | Description |
---|---|
System.String | Pascal Case String |
ToHexadecimalString(Byte[])
Create a hexadecimal string for the given bytes.
Declaration
public static string ToHexadecimalString(this byte[] data)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | data | The input bytes. |
Returns
Type | Description |
---|---|
System.String | The output hexadecimal string. |
ToLongOp(OpCode)
Get the long form opcode for any short form opcode.
Declaration
public static OpCode ToLongOp(this OpCode op)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.Cil.OpCode | op | The short form opcode. |
Returns
Type | Description |
---|---|
Mono.Cecil.Cil.OpCode | The long form opcode. |
ToShortOp(OpCode)
Get the short form opcode for any long form opcode.
Declaration
public static OpCode ToShortOp(this OpCode op)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.Cil.OpCode | op | The long form opcode. |
Returns
Type | Description |
---|---|
Mono.Cecil.Cil.OpCode | The short form opcode. |
TryCastDelegate(Delegate, Type, out Delegate)
Declaration
public static bool TryCastDelegate(this Delegate source, Type type, out Delegate result)
Parameters
Type | Name | Description |
---|---|---|
System.Delegate | source | |
System.Type | type | |
System.Delegate | result |
Returns
Type | Description |
---|---|
System.Boolean |
TryCastDelegate<T>(Delegate, out T)
Declaration
public static bool TryCastDelegate<T>(this Delegate source, out T result)
where T : class
Parameters
Type | Name | Description |
---|---|---|
System.Delegate | source | |
T | result |
Returns
Type | Description |
---|---|
System.Boolean |
Type Parameters
Name | Description |
---|---|
T |
Update(GenericParameter, Int32, GenericParameterType)
Force-update a generic parameter's position and type.
Declaration
public static GenericParameter Update(this GenericParameter param, int position, GenericParameterType type)
Parameters
Type | Name | Description |
---|---|---|
Mono.Cecil.GenericParameter | param | The generic parameter to update. |
System.Int32 | position | The new position. |
Mono.Cecil.GenericParameterType | type | The new type. |
Returns
Type | Description |
---|---|
Mono.Cecil.GenericParameter | The updated generic parameter. |
WriteNullTerminatedString(BinaryWriter, String)
Write the string to the BinaryWriter in a C-friendly format.
Declaration
public static void WriteNullTerminatedString(this BinaryWriter stream, string text)
Parameters
Type | Name | Description |
---|---|---|
System.IO.BinaryWriter | stream | The output which the method writes to. |
System.String | text | The input string. |