docs/api/HarmonyLib.AccessToolsExtensions.html
Adds extensions to Type for a lot of AccessTools methods
System.Object
AccessToolsExtensions
public static class AccessToolsExtensions
Gets the reflection information for a constructor by searching the type and all its super types
public static ConstructorInfo Constructor(this Type type, Type[] parameters = null, bool searchForStatic = false)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type where the constructor is declared
| | System.Type[] | parameters |
Optional parameters to target a specific overload of the method
| | System.Boolean | searchForStatic |
Optional parameters to only consider static constructors
|
| Type | Description |
|---|---|
| System.Reflection.ConstructorInfo |
A constructor info or null when type is null or when the method cannot be found
|
Creates an (possibly uninitialized) instance of a given type
public static object CreateInstance(this Type type)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type
|
| Type | Description |
|---|---|
| System.Object |
The new instance
|
Gets the reflection information for a directly declared constructor
public static ConstructorInfo DeclaredConstructor(this Type type, Type[] parameters = null, bool searchForStatic = false)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type where the constructor is declared
| | System.Type[] | parameters |
Optional parameters to target a specific overload of the constructor
| | System.Boolean | searchForStatic |
Optional parameters to only consider static constructors
|
| Type | Description |
|---|---|
| System.Reflection.ConstructorInfo |
A constructor info or null when type is null or when the constructor cannot be found
|
Gets the reflection information for a directly declared event
public static EventInfo DeclaredEvent(this Type type, string name)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type where the event is declared
| | System.String | name |
The name of the event (case sensitive)
|
| Type | Description |
|---|---|
| System.Reflection.EventInfo |
An event or null when type/name is null or when the event cannot be found
|
Gets the reflection information for the add method of a directly declared event
public static MethodInfo DeclaredEventAdder(this Type type, string name)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type where the event is declared
| | System.String | name |
The name of the event (case sensitive)
|
| Type | Description |
|---|---|
| System.Reflection.MethodInfo |
A method or null when type/name is null or when the event cannot be found
|
Gets the reflection information for the remove method of a directly declared event
public static MethodInfo DeclaredEventRemover(this Type type, string name)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type where the event is declared
| | System.String | name |
The name of the event (case sensitive)
|
| Type | Description |
|---|---|
| System.Reflection.MethodInfo |
A method or null when type/name is null or when the event cannot be found
|
Gets the reflection information for a field
public static FieldInfo DeclaredField(this Type type, int idx)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type where the field is declared
| | System.Int32 | idx |
The zero-based index of the field inside the class definition
|
| Type | Description |
|---|---|
| System.Reflection.FieldInfo |
A field or null when type is null or when the field cannot be found
|
Gets the reflection information for a directly declared field
public static FieldInfo DeclaredField(this Type type, string name)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type where the field is defined
| | System.String | name |
The name of the field
|
| Type | Description |
|---|---|
| System.Reflection.FieldInfo |
A field or null when type/name is null or when the field cannot be found
|
Gets the reflection information for a directly declared finalizer
public static MethodInfo DeclaredFinalizer(this Type type)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type that defines the finalizer
|
| Type | Description |
|---|---|
| System.Reflection.MethodInfo |
A method or null when type is null or when the finalizer cannot be found
|
Gets the reflection information for a directly declared indexer property
public static PropertyInfo DeclaredIndexer(this Type type, Type[] parameters = null)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type where the indexer property is declared
| | System.Type[] | parameters |
Optional parameters to target a specific overload of multiple indexers
|
| Type | Description |
|---|---|
| System.Reflection.PropertyInfo |
An indexer property or null when type is null or when it cannot be found
|
Gets the reflection information for the getter method of a directly declared indexer property
public static MethodInfo DeclaredIndexerGetter(this Type type, Type[] parameters = null)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type where the indexer property is declared
| | System.Type[] | parameters |
Optional parameters to target a specific overload of multiple indexers
|
| Type | Description |
|---|---|
| System.Reflection.MethodInfo |
A method or null when type is null or when indexer property cannot be found
|
Gets the reflection information for the setter method of a directly declared indexer property
public static MethodInfo DeclaredIndexerSetter(this Type type, Type[] parameters)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type where the indexer property is declared
| | System.Type[] | parameters |
Optional parameters to target a specific overload of multiple indexers
|
| Type | Description |
|---|---|
| System.Reflection.MethodInfo |
A method or null when type is null or when indexer property cannot be found
|
Gets the reflection information for a directly declared method
public static MethodInfo DeclaredMethod(this Type type, string name, Type[] parameters = null, Type[] generics = null)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type where the method is declared
| | System.String | name |
The name of the method (case sensitive)
| | System.Type[] | parameters |
Optional parameters to target a specific overload of the method
| | System.Type[] | generics |
Optional list of types that define the generic version of the method
|
| Type | Description |
|---|---|
| System.Reflection.MethodInfo |
A method or null when type/name is null or when the method cannot be found
|
Gets the reflection information for a directly declared property
public static PropertyInfo DeclaredProperty(this Type type, string name)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type where the property is declared
| | System.String | name |
The name of the property (case sensitive)
|
| Type | Description |
|---|---|
| System.Reflection.PropertyInfo |
A property or null when type/name is null or when the property cannot be found
|
Gets the reflection information for the getter method of a directly declared property
public static MethodInfo DeclaredPropertyGetter(this Type type, string name)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type where the property is declared
| | System.String | name |
The name of the property (case sensitive)
|
| Type | Description |
|---|---|
| System.Reflection.MethodInfo |
A method or null when type/name is null or when the property cannot be found
|
Gets the reflection information for the setter method of a directly declared property
public static MethodInfo DeclaredPropertySetter(this Type type, string name)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type where the property is declared
| | System.String | name |
The name of the property (case sensitive)
|
| Type | Description |
|---|---|
| System.Reflection.MethodInfo |
A method or null when type/name is null or when the property cannot be found
|
Gets the reflection information for an event by searching the type and all its super types
public static EventInfo Event(this Type type, string name)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type
| | System.String | name |
The name
|
| Type | Description |
|---|---|
| System.Reflection.EventInfo |
An event or null when type/name is null or when the event cannot be found
|
Gets the reflection information for the add method of an event by searching the type and all its super types
public static MethodInfo EventAdder(this Type type, string name)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type
| | System.String | name |
The name
|
| Type | Description |
|---|---|
| System.Reflection.MethodInfo |
A method or null when type/name is null or when the event cannot be found
|
Gets the reflection information for the remove method of an event by searching the type and all its super types
public static MethodInfo EventRemover(this Type type, string name)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type
| | System.String | name |
The name
|
| Type | Description |
|---|---|
| System.Reflection.MethodInfo |
A method or null when type/name is null or when the event cannot be found
|
Gets the reflection information for a field by searching the type and all its super types
public static FieldInfo Field(this Type type, string name)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type where the field is defined
| | System.String | name |
The name of the field (case sensitive)
|
| Type | Description |
|---|---|
| System.Reflection.FieldInfo |
A field or null when type/name is null or when the field cannot be found
|
Creates a field reference delegate for an instance field of a class or static field (NOT an instance field of a struct)
public static AccessTools.FieldRef<object, F> FieldRefAccess<F>(this Type type, string fieldName)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The type that defines the field, or derived class of this type; must not be a struct type unless the field is static
| | System.String | fieldName |
The name of the field
|
| Type | Description |
|---|---|
| AccessTools.FieldRef\ |
A readable/assignable AccessTools.FieldRef<T, F> delegate with T=object (for static fields, the instance delegate parameter is ignored)
|
| Name | Description |
|---|---|
| F |
The type of the field; or if the field's type is a reference type (a class or interface, NOT a struct or other value type), a type that System.Type.IsAssignableFrom(System.Type) that type; or if the field's type is an enum type, either that type or the underlying integral type of that enum type
|
This method is meant for cases where the given type is only known at runtime and thus can't be used as a type parameter T in e.g. FieldRefAccess<T, F>(String).
This method supports static fields, even those defined in structs, for legacy reasons. Consider using StaticFieldRefAccess<F>(Type, String) (and other overloads) instead for static fields.
Gets the reflection information for a finalizer
public static MethodInfo Finalizer(this Type type)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type that defines the finalizer
|
| Type | Description |
|---|---|
| System.Reflection.MethodInfo |
A method or null when type is null or when the finalizer cannot be found
|
Applies a function going up the type hierarchy and stops at the first non-null result
public static T FindIncludingBaseTypes<T>(this Type type, Func<Type, T> func)
where T : class
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type to start with
| | System.Func\ | func |
The evaluation function returning T
|
| Type | Description |
|---|---|
| T |
The first non-null result, or null if no match
|
| Name | Description |
|---|---|
| T |
Result type of func()
|
The type hierarchy of a class or value type (including struct) does NOT include implemented interfaces, and the type hierarchy of an interface is only itself (regardless of whether that interface implements other interfaces). The top-most type in the type hierarchy of all non-interface types (including value types) is System.Object.
Applies a function going into inner types and stops at the first non-null result
public static T FindIncludingInnerTypes<T>(this Type type, Func<Type, T> func)
where T : class
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type to start with
| | System.Func\ | func |
The evaluation function returning T
|
| Type | Description |
|---|---|
| T |
The first non-null result, or null if no match
|
| Name | Description |
|---|---|
| T |
Generic type parameter
|
Given a type, returns the first constructor matching a predicate
public static ConstructorInfo FirstConstructor(this Type type, Func<ConstructorInfo, bool> predicate)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type to start searching at
| | System.Func\ | predicate |
The predicate to search with
|
| Type | Description |
|---|---|
| System.Reflection.ConstructorInfo |
The constructor info or null if type/predicate is null or if a type with that name cannot be found
|
Given a type, returns the first inner type matching a recursive search with a predicate
public static Type FirstInner(this Type type, Func<Type, bool> predicate)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type to start searching at
| | System.Func\ | predicate |
The predicate to search with
|
| Type | Description |
|---|---|
| System.Type |
The inner type or null if type/predicate is null or if a type with that name cannot be found
|
Given a type, returns the first method matching a predicate
public static MethodInfo FirstMethod(this Type type, Func<MethodInfo, bool> predicate)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type to start searching at
| | System.Func\ | predicate |
The predicate to search with
|
| Type | Description |
|---|---|
| System.Reflection.MethodInfo |
The method or null if type/predicate is null or if a type with that name cannot be found
|
Given a type, returns the first property matching a predicate
public static PropertyInfo FirstProperty(this Type type, Func<PropertyInfo, bool> predicate)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type to start searching at
| | System.Func\ | predicate |
The predicate to search with
|
| Type | Description |
|---|---|
| System.Reflection.PropertyInfo |
The property or null if type/predicate is null or if a type with that name cannot be found
|
Gets reflection information for all declared constructors
public static List<ConstructorInfo> GetDeclaredConstructors(this Type type, bool? searchForStatic = default(bool? ))
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type where the constructors are declared
| | System.Nullable\ | searchForStatic |
Optional parameters to only consider static constructors
|
| Type | Description |
|---|---|
| System.Collections.Generic.List\ |
A list of constructor infos
|
Gets reflection information for all declared fields
public static List<FieldInfo> GetDeclaredFields(this Type type)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type where the fields are declared
|
| Type | Description |
|---|---|
| System.Collections.Generic.List\ |
A list of fields
|
Gets reflection information for all declared methods
public static List<MethodInfo> GetDeclaredMethods(this Type type)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type where the methods are declared
|
| Type | Description |
|---|---|
| System.Collections.Generic.List\ |
A list of methods
|
Gets reflection information for all declared properties
public static List<PropertyInfo> GetDeclaredProperties(this Type type)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type where the properties are declared
|
| Type | Description |
|---|---|
| System.Collections.Generic.List\ |
A list of properties
|
Gets default value for a specific type
public static object GetDefaultValue(this Type type)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type
|
| Type | Description |
|---|---|
| System.Object |
The default value
|
Gets the names of all fields that are declared in a type
public static List<string> GetFieldNames(this Type type)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The declaring class/type
|
| Type | Description |
|---|---|
| System.Collections.Generic.List\ |
A list of field names
|
Gets the names of all method that are declared in a type
public static List<string> GetMethodNames(this Type type)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The declaring class/type
|
| Type | Description |
|---|---|
| System.Collections.Generic.List\ |
A list of method names
|
Gets the names of all properties that are declared in a type
public static List<string> GetPropertyNames(this Type type)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The declaring class/type
|
| Type | Description |
|---|---|
| System.Collections.Generic.List\ |
A list of property names
|
Gets the reflection information for an indexer property by searching the type and all its super types
public static PropertyInfo Indexer(this Type type, Type[] parameters = null)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type
| | System.Type[] | parameters |
Optional parameters to target a specific overload of multiple indexers
|
| Type | Description |
|---|---|
| System.Reflection.PropertyInfo |
An indexer property or null when type is null or when it cannot be found
|
Gets the reflection information for the getter method of an indexer property by searching the type and all its super types
public static MethodInfo IndexerGetter(this Type type, Type[] parameters = null)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type
| | System.Type[] | parameters |
Optional parameters to target a specific overload of multiple indexers
|
| Type | Description |
|---|---|
| System.Reflection.MethodInfo |
A method or null when type is null or when the indexer property cannot be found
|
Gets the reflection information for the setter method of an indexer property by searching the type and all its super types
public static MethodInfo IndexerSetter(this Type type, Type[] parameters = null)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type
| | System.Type[] | parameters |
Optional parameters to target a specific overload of multiple indexers
|
| Type | Description |
|---|---|
| System.Reflection.MethodInfo |
A method or null when type is null or when the indexer property cannot be found
|
Given a type, returns the first inner type matching a recursive search by name
public static Type Inner(this Type type, string name)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type to start searching at
| | System.String | name |
The name of the inner type (case sensitive)
|
| Type | Description |
|---|---|
| System.Type |
The inner type or null if type/name is null or if a type with that name cannot be found
|
Enumerates all inner types (non-recursive)
public static IEnumerable<Type> InnerTypes(this Type type)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type to start with
|
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable\ |
An enumeration of all inner System.Type
|
Tests if a type is a class
public static bool IsClass(this Type type)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The type
|
| Type | Description |
|---|---|
| System.Boolean |
True if the type is a class
|
Tests if a type is a floating point type
public static bool IsFloatingPoint(this Type type)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The type
|
| Type | Description |
|---|---|
| System.Boolean |
True if the type represents some floating point
|
Tests if a type is an integer type
public static bool IsInteger(this Type type)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The type
|
| Type | Description |
|---|---|
| System.Boolean |
True if the type represents some integer
|
Tests if a type is a numerical type
public static bool IsNumber(this Type type)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The type
|
| Type | Description |
|---|---|
| System.Boolean |
True if the type represents some number
|
Tests whether a type is static, as defined in C#
public static bool IsStatic(this Type type)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The type
|
| Type | Description |
|---|---|
| System.Boolean |
True if the type is static
|
Tests if a type is a struct
public static bool IsStruct(this Type type)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The type
|
| Type | Description |
|---|---|
| System.Boolean |
True if the type is a struct
|
Tests if a type is a value type
public static bool IsValue(this Type type)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The type
|
| Type | Description |
|---|---|
| System.Boolean |
True if the type is a value type
|
Tests if a type is void
public static bool IsVoid(this Type type)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The type
|
| Type | Description |
|---|---|
| System.Boolean |
True if the type is void
|
Gets the reflection information for a method by searching the type and all its super types
public static MethodInfo Method(this Type type, string name, Type[] parameters = null, Type[] generics = null)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type where the method is declared
| | System.String | name |
The name of the method (case sensitive)
| | System.Type[] | parameters |
Optional parameters to target a specific overload of the method
| | System.Type[] | generics |
Optional list of types that define the generic version of the method
|
| Type | Description |
|---|---|
| System.Reflection.MethodInfo |
A method or null when type/name is null or when the method cannot be found
|
Gets the reflection information for a property by searching the type and all its super types
public static PropertyInfo Property(this Type type, string name)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type
| | System.String | name |
The name
|
| Type | Description |
|---|---|
| System.Reflection.PropertyInfo |
A property or null when type/name is null or when the property cannot be found
|
Gets the reflection information for the getter method of a property by searching the type and all its super types
public static MethodInfo PropertyGetter(this Type type, string name)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type
| | System.String | name |
The name
|
| Type | Description |
|---|---|
| System.Reflection.MethodInfo |
A method or null when type/name is null or when the property cannot be found
|
Gets the reflection information for the setter method of a property by searching the type and all its super types
public static MethodInfo PropertySetter(this Type type, string name)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type
| | System.String | name |
The name
|
| Type | Description |
|---|---|
| System.Reflection.MethodInfo |
A method or null when type/name is null or when the property cannot be found
|
Creates a static field reference
public static F StaticFieldRefAccess<F>(this Type type, string fieldName)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The type (can be class or struct) the field is defined in
| | System.String | fieldName |
The name of the field
|
| Type | Description |
|---|---|
| F |
A readable/assignable reference to the field
|
| Name | Description |
|---|---|
| F |
The type of the field; or if the field's type is a reference type (a class or interface, NOT a struct or other value type), a type that System.Type.IsAssignableFrom(System.Type) that type; or if the field's type is an enum type, either that type or the underlying integral type of that enum type
|
Throws a missing member runtime exception
public static void ThrowMissingMemberException(this Type type, params string[] names)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The type that is involved
| | System.String[] | names |
A list of names
|