Class AccessToolsExtensions
- Namespace
- HarmonyLib
- Assembly
- 0Harmony.dll
Adds extensions to Type for a lot of AccessTools methods
public static class AccessToolsExtensions
- Inheritance
-
objectAccessToolsExtensions
Methods
Constructor(Type, Type[], bool)
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)
Parameters
typeTypeThe class/type where the constructor is declared
parametersType[]Optional parameters to target a specific overload of the method
searchForStaticboolOptional parameters to only consider static constructors
Returns
- ConstructorInfo
A constructor info or null when type is null or when the method cannot be found
CreateInstance(Type)
Creates an (possibly uninitialized) instance of a given type
public static object CreateInstance(this Type type)
Parameters
typeTypeThe class/type
Returns
- object
The new instance
DeclaredConstructor(Type, Type[], bool)
Gets the reflection information for a directly declared constructor
public static ConstructorInfo DeclaredConstructor(this Type type, Type[] parameters = null, bool searchForStatic = false)
Parameters
typeTypeThe class/type where the constructor is declared
parametersType[]Optional parameters to target a specific overload of the constructor
searchForStaticboolOptional parameters to only consider static constructors
Returns
- ConstructorInfo
A constructor info or null when type is null or when the constructor cannot be found
DeclaredEvent(Type, string)
Gets the reflection information for a directly declared event
public static EventInfo DeclaredEvent(this Type type, string name)
Parameters
typeTypeThe class/type where the event is declared
namestringThe name of the event (case sensitive)
Returns
- EventInfo
An event or null when type/name is null or when the event cannot be found
DeclaredEventAdder(Type, string)
Gets the reflection information for the add method of a directly declared event
public static MethodInfo DeclaredEventAdder(this Type type, string name)
Parameters
typeTypeThe class/type where the event is declared
namestringThe name of the event (case sensitive)
Returns
- MethodInfo
A method or null when type/name is null or when the event cannot be found
DeclaredEventRemover(Type, string)
Gets the reflection information for the remove method of a directly declared event
public static MethodInfo DeclaredEventRemover(this Type type, string name)
Parameters
typeTypeThe class/type where the event is declared
namestringThe name of the event (case sensitive)
Returns
- MethodInfo
A method or null when type/name is null or when the event cannot be found
DeclaredField(Type, int)
Gets the reflection information for a field
public static FieldInfo DeclaredField(this Type type, int idx)
Parameters
typeTypeThe class/type where the field is declared
idxintThe zero-based index of the field inside the class definition
Returns
- FieldInfo
A field or null when type is null or when the field cannot be found
DeclaredField(Type, string)
Gets the reflection information for a directly declared field
public static FieldInfo DeclaredField(this Type type, string name)
Parameters
typeTypeThe class/type where the field is defined
namestringThe name of the field
Returns
- FieldInfo
A field or null when type/name is null or when the field cannot be found
DeclaredFinalizer(Type)
Gets the reflection information for a directly declared finalizer
public static MethodInfo DeclaredFinalizer(this Type type)
Parameters
typeTypeThe class/type that defines the finalizer
Returns
- MethodInfo
A method or null when type is null or when the finalizer cannot be found
DeclaredIndexer(Type, Type[])
Gets the reflection information for a directly declared indexer property
public static PropertyInfo DeclaredIndexer(this Type type, Type[] parameters = null)
Parameters
typeTypeThe class/type where the indexer property is declared
parametersType[]Optional parameters to target a specific overload of multiple indexers
Returns
- PropertyInfo
An indexer property or null when type is null or when it cannot be found
DeclaredIndexerGetter(Type, Type[])
Gets the reflection information for the getter method of a directly declared indexer property
public static MethodInfo DeclaredIndexerGetter(this Type type, Type[] parameters = null)
Parameters
typeTypeThe class/type where the indexer property is declared
parametersType[]Optional parameters to target a specific overload of multiple indexers
Returns
- MethodInfo
A method or null when type is null or when indexer property cannot be found
DeclaredIndexerSetter(Type, Type[])
Gets the reflection information for the setter method of a directly declared indexer property
public static MethodInfo DeclaredIndexerSetter(this Type type, Type[] parameters)
Parameters
typeTypeThe class/type where the indexer property is declared
parametersType[]Optional parameters to target a specific overload of multiple indexers
Returns
- MethodInfo
A method or null when type is null or when indexer property cannot be found
DeclaredMethod(Type, string, Type[], Type[])
Gets the reflection information for a directly declared method
public static MethodInfo DeclaredMethod(this Type type, string name, Type[] parameters = null, Type[] generics = null)
Parameters
typeTypeThe class/type where the method is declared
namestringThe name of the method (case sensitive)
parametersType[]Optional parameters to target a specific overload of the method
genericsType[]Optional list of types that define the generic version of the method
Returns
- MethodInfo
A method or null when type/name is null or when the method cannot be found
DeclaredProperty(Type, string)
Gets the reflection information for a directly declared property
public static PropertyInfo DeclaredProperty(this Type type, string name)
Parameters
typeTypeThe class/type where the property is declared
namestringThe name of the property (case sensitive)
Returns
- PropertyInfo
A property or null when type/name is null or when the property cannot be found
DeclaredPropertyGetter(Type, string)
Gets the reflection information for the getter method of a directly declared property
public static MethodInfo DeclaredPropertyGetter(this Type type, string name)
Parameters
typeTypeThe class/type where the property is declared
namestringThe name of the property (case sensitive)
Returns
- MethodInfo
A method or null when type/name is null or when the property cannot be found
DeclaredPropertySetter(Type, string)
Gets the reflection information for the setter method of a directly declared property
public static MethodInfo DeclaredPropertySetter(this Type type, string name)
Parameters
typeTypeThe class/type where the property is declared
namestringThe name of the property (case sensitive)
Returns
- MethodInfo
A method or null when type/name is null or when the property cannot be found
Event(Type, string)
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)
Parameters
typeTypeThe class/type
namestringThe name
Returns
- EventInfo
An event or null when type/name is null or when the event cannot be found
EventAdder(Type, string)
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)
Parameters
typeTypeThe class/type
namestringThe name
Returns
- MethodInfo
A method or null when type/name is null or when the event cannot be found
EventRemover(Type, string)
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)
Parameters
typeTypeThe class/type
namestringThe name
Returns
- MethodInfo
A method or null when type/name is null or when the event cannot be found
Field(Type, string)
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)
Parameters
typeTypeThe class/type where the field is defined
namestringThe name of the field (case sensitive)
Returns
- FieldInfo
A field or null when type/name is null or when the field cannot be found
FieldRefAccess<F>(Type, string)
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)
Parameters
typeTypeThe type that defines the field, or derived class of this type; must not be a struct type unless the field is static
fieldNamestringThe name of the field
Returns
- AccessTools.FieldRef<object, F>
A readable/assignable AccessTools.FieldRef<T, F> delegate with
T=object(for static fields, theinstancedelegate parameter is ignored)
Type Parameters
FThe 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 is assignable from that type; or if the field's type is an enum type, either that type or the underlying integral type of that enum type
Remarks
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.
Finalizer(Type)
Gets the reflection information for a finalizer
public static MethodInfo Finalizer(this Type type)
Parameters
typeTypeThe class/type that defines the finalizer
Returns
- MethodInfo
A method or null when type is null or when the finalizer cannot be found
FindIncludingBaseTypes<T>(Type, Func<Type, T>)
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
Parameters
typeTypeThe class/type to start with
funcFunc<Type, T>The evaluation function returning T
Returns
- T
The first non-
nullresult, ornullif no match
Type Parameters
TResult type of func()
Remarks
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 object.
FindIncludingInnerTypes<T>(Type, Func<Type, T>)
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
Parameters
typeTypeThe class/type to start with
funcFunc<Type, T>The evaluation function returning T
Returns
- T
The first non-
nullresult, ornullif no match
Type Parameters
TGeneric type parameter
FirstConstructor(Type, Func<ConstructorInfo, bool>)
Given a type, returns the first constructor matching a predicate
public static ConstructorInfo FirstConstructor(this Type type, Func<ConstructorInfo, bool> predicate)
Parameters
typeTypeThe class/type to start searching at
predicateFunc<ConstructorInfo, bool>The predicate to search with
Returns
- ConstructorInfo
The constructor info or null if type/predicate is null or if a type with that name cannot be found
FirstInner(Type, Func<Type, bool>)
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)
Parameters
typeTypeThe class/type to start searching at
predicateFunc<Type, bool>The predicate to search with
Returns
- Type
The inner type or null if type/predicate is null or if a type with that name cannot be found
FirstMethod(Type, Func<MethodInfo, bool>)
Given a type, returns the first method matching a predicate
public static MethodInfo FirstMethod(this Type type, Func<MethodInfo, bool> predicate)
Parameters
typeTypeThe class/type to start searching at
predicateFunc<MethodInfo, bool>The predicate to search with
Returns
- MethodInfo
The method or null if type/predicate is null or if a type with that name cannot be found
FirstProperty(Type, Func<PropertyInfo, bool>)
Given a type, returns the first property matching a predicate
public static PropertyInfo FirstProperty(this Type type, Func<PropertyInfo, bool> predicate)
Parameters
typeTypeThe class/type to start searching at
predicateFunc<PropertyInfo, bool>The predicate to search with
Returns
- PropertyInfo
The property or null if type/predicate is null or if a type with that name cannot be found
GetDeclaredConstructors(Type, bool?)
Gets reflection information for all declared constructors
public static List<ConstructorInfo> GetDeclaredConstructors(this Type type, bool? searchForStatic = null)
Parameters
typeTypeThe class/type where the constructors are declared
searchForStaticbool?Optional parameters to only consider static constructors
Returns
- List<ConstructorInfo>
A list of constructor infos
GetDeclaredFields(Type)
Gets reflection information for all declared fields
public static List<FieldInfo> GetDeclaredFields(this Type type)
Parameters
typeTypeThe class/type where the fields are declared
Returns
- List<FieldInfo>
A list of fields
GetDeclaredMethods(Type)
Gets reflection information for all declared methods
public static List<MethodInfo> GetDeclaredMethods(this Type type)
Parameters
typeTypeThe class/type where the methods are declared
Returns
- List<MethodInfo>
A list of methods
GetDeclaredProperties(Type)
Gets reflection information for all declared properties
public static List<PropertyInfo> GetDeclaredProperties(this Type type)
Parameters
typeTypeThe class/type where the properties are declared
Returns
- List<PropertyInfo>
A list of properties
GetDefaultValue(Type)
Gets default value for a specific type
public static object GetDefaultValue(this Type type)
Parameters
typeTypeThe class/type
Returns
- object
The default value
GetFieldNames(Type)
Gets the names of all fields that are declared in a type
public static List<string> GetFieldNames(this Type type)
Parameters
typeTypeThe declaring class/type
Returns
- List<string>
A list of field names
GetMethodNames(Type)
Gets the names of all method that are declared in a type
public static List<string> GetMethodNames(this Type type)
Parameters
typeTypeThe declaring class/type
Returns
- List<string>
A list of method names
GetPropertyNames(Type)
Gets the names of all properties that are declared in a type
public static List<string> GetPropertyNames(this Type type)
Parameters
typeTypeThe declaring class/type
Returns
- List<string>
A list of property names
Indexer(Type, Type[])
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)
Parameters
typeTypeThe class/type
parametersType[]Optional parameters to target a specific overload of multiple indexers
Returns
- PropertyInfo
An indexer property or null when type is null or when it cannot be found
IndexerGetter(Type, Type[])
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)
Parameters
typeTypeThe class/type
parametersType[]Optional parameters to target a specific overload of multiple indexers
Returns
- MethodInfo
A method or null when type is null or when the indexer property cannot be found
IndexerSetter(Type, Type[])
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)
Parameters
typeTypeThe class/type
parametersType[]Optional parameters to target a specific overload of multiple indexers
Returns
- MethodInfo
A method or null when type is null or when the indexer property cannot be found
Inner(Type, string)
Given a type, returns the first inner type matching a recursive search by name
public static Type Inner(this Type type, string name)
Parameters
typeTypeThe class/type to start searching at
namestringThe name of the inner type (case sensitive)
Returns
- Type
The inner type or null if type/name is null or if a type with that name cannot be found
InnerTypes(Type)
Enumerates all inner types (non-recursive)
public static IEnumerable<Type> InnerTypes(this Type type)
Parameters
typeTypeThe class/type to start with
Returns
- IEnumerable<Type>
An enumeration of all inner System.Type
IsClass(Type)
Tests if a type is a class
public static bool IsClass(this Type type)
Parameters
typeTypeThe type
Returns
- bool
True if the type is a class
IsFloatingPoint(Type)
Tests if a type is a floating point type
public static bool IsFloatingPoint(this Type type)
Parameters
typeTypeThe type
Returns
- bool
True if the type represents some floating point
IsInteger(Type)
Tests if a type is an integer type
public static bool IsInteger(this Type type)
Parameters
typeTypeThe type
Returns
- bool
True if the type represents some integer
IsNumber(Type)
Tests if a type is a numerical type
public static bool IsNumber(this Type type)
Parameters
typeTypeThe type
Returns
- bool
True if the type represents some number
IsStruct(Type)
Tests if a type is a struct
public static bool IsStruct(this Type type)
Parameters
typeTypeThe type
Returns
- bool
True if the type is a struct
IsValue(Type)
Tests if a type is a value type
public static bool IsValue(this Type type)
Parameters
typeTypeThe type
Returns
- bool
True if the type is a value type
IsVoid(Type)
Tests if a type is void
public static bool IsVoid(this Type type)
Parameters
typeTypeThe type
Returns
- bool
True if the type is void
Method(Type, string, Type[], Type[])
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)
Parameters
typeTypeThe class/type where the method is declared
namestringThe name of the method (case sensitive)
parametersType[]Optional parameters to target a specific overload of the method
genericsType[]Optional list of types that define the generic version of the method
Returns
- MethodInfo
A method or null when type/name is null or when the method cannot be found
Property(Type, string)
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)
Parameters
typeTypeThe class/type
namestringThe name
Returns
- PropertyInfo
A property or null when type/name is null or when the property cannot be found
PropertyGetter(Type, string)
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)
Parameters
typeTypeThe class/type
namestringThe name
Returns
- MethodInfo
A method or null when type/name is null or when the property cannot be found
PropertySetter(Type, string)
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)
Parameters
typeTypeThe class/type
namestringThe name
Returns
- MethodInfo
A method or null when type/name is null or when the property cannot be found
StaticFieldRefAccess<F>(Type, string)
Creates a static field reference
public static ref F StaticFieldRefAccess<F>(this Type type, string fieldName)
Parameters
typeTypeThe type (can be class or struct) the field is defined in
fieldNamestringThe name of the field
Returns
- F
A readable/assignable reference to the field
Type Parameters
FThe 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 is assignable from that type; or if the field's type is an enum type, either that type or the underlying integral type of that enum type
ThrowMissingMemberException(Type, params string[])
Throws a missing member runtime exception
public static void ThrowMissingMemberException(this Type type, params string[] names)
Parameters
typeTypeThe type that is involved
namesstring[]A list of names