Class ReflectionUtils
Utility methods for common reflection-based operations.
Inherited Members
Namespace: Unity.XR.CoreUtils
Syntax
public static class ReflectionUtils
Methods
FindType(Func<Type, Boolean>)
Search all assemblies for a type that matches a given predicate delegate.
Declaration
public static Type FindType(Func<Type, bool> predicate)
Parameters
Type | Name | Description |
---|---|---|
Func<Type, Boolean> | predicate | The predicate function. Must return true for the type that matches the search. |
Returns
Type | Description |
---|---|
Type | The first type for which |
FindTypeByFullName(String)
Find a type in any assembly by its full name.
Declaration
public static Type FindTypeByFullName(string fullName)
Parameters
Type | Name | Description |
---|---|---|
String | fullName | The name of the type as returned by FullName. |
Returns
Type | Description |
---|---|
Type | The type found, or null if no matching type exists. |
FindTypeInAssemblyByFullName(String, String)
Searches for a type by assembly simple name and its FullName. an assembly with the given simple name and returns the type with the given full name in that assembly
Declaration
public static Type FindTypeInAssemblyByFullName(string assemblyName, string typeName)
Parameters
Type | Name | Description |
---|---|---|
String | assemblyName | Simple name of the assembly (GetName()). |
String | typeName | Full name of the type to find (FullName). |
Returns
Type | Description |
---|---|
Type | The type if found, otherwise null |
FindTypesBatch(List<Func<Type, Boolean>>, List<Type>)
Search all assemblies for a set of types that matches any one of a set of predicates.
Declaration
public static void FindTypesBatch(List<Func<Type, bool>> predicates, List<Type> resultList)
Parameters
Type | Name | Description |
---|---|---|
List<Func<Type, Boolean>> | predicates | The predicate functions. A predicate function must return true for the type that matches the search and should only match one type. |
List<Type> | resultList | The list to which found types will be added. The list must have
the same number of elements as the |
Remarks
This function tests each predicate against each type in each assembly. If the predicate returns
true for a type, then that Type object is assigned to the corresponding index of
the resultList
. If a predicate returns true for more than one type, then the
last matching result is used. If no type matches the predicate, then that index of resultList
is left unchanged.
FindTypesByFullNameBatch(List<String>, List<Type>)
Searches all assemblies for a set of types by their FullName strings.
Declaration
public static void FindTypesByFullNameBatch(List<string> typeNames, List<Type> resultList)
Parameters
Type | Name | Description |
---|---|---|
List<String> | typeNames | A list containing the FullName strings of the types to find. |
List<Type> | resultList | An empty list to which any matching Type objects are added. A
result in |
Remarks
If a type name in typeNames
is not found, then the corresponding index of resultList
is set to null
.
ForEachAssembly(Action<Assembly>)
Executes a delegate function for every assembly that can be loaded.
Declaration
public static void ForEachAssembly(Action<Assembly> callback)
Parameters
Type | Name | Description |
---|---|---|
Action<Assembly> | callback | The callback method to execute for each assembly. |
Remarks
ForEachAssembly
iterates through all assemblies and executes a method on each one.
If an ReflectionTypeLoadException is thrown, it is caught and ignored.
ForEachType(Action<Type>)
Executes a delegate function for each type in every assembly.
Declaration
public static void ForEachType(Action<Type> callback)
Parameters
Type | Name | Description |
---|---|---|
Action<Type> | callback | The callback to execute. |
GetFieldsWithAttribute(Type, List<FieldInfo>, BindingFlags)
Declaration
public static void GetFieldsWithAttribute(Type attributeType, List<FieldInfo> fields, BindingFlags bindingAttr = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
Parameters
Type | Name | Description |
---|---|---|
Type | attributeType | |
List<FieldInfo> | fields | |
BindingFlags | bindingAttr |
NicifyVariableName(String)
Cleans up a variable name for display in UI.
Declaration
public static string NicifyVariableName(string name)
Parameters
Type | Name | Description |
---|---|---|
String | name | The variable name to clean up. |
Returns
Type | Description |
---|---|
String | The display name for the variable. |
PreWarmTypeCache()
Caches type information from all currently loaded assemblies.
Declaration
public static void PreWarmTypeCache()