Class ReflectionHelpers
An ad-hoc collection of helpers for reflection, used by Cinemachine or its editor tools in various places
Namespace: Cinemachine.Utility
Syntax
public static class ReflectionHelpers : object
Methods
AccessInternalField<T>(Type, Object, String)
Cheater extension to access internal field of an object
Declaration
public static T AccessInternalField<T>(this Type type, object obj, string memberName)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | type | The type of the field |
| Object | obj | The object to access |
| String | memberName | The string name of the field to access |
Returns
| Type | Description |
|---|---|
| T | The value of the field in the objects |
Type Parameters
| Name | Description |
|---|---|
| T | The field type |
CopyFields(System.Object, System.Object, System.Reflection.BindingFlags)
Copy the fields from one object to another
Declaration
public static void CopyFields(System.Object src, System.Object dst, System.Reflection.BindingFlags bindingAttr = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | src | The source object to copy from |
| System.Object | dst | The destination object to copy to |
| System.Reflection.BindingFlags | bindingAttr | The mask to filter the attributes. Only those fields that get caught in the filter will be copied |
GetFieldPath<TType, TValue>(Expression<Func<TType, TValue>>)
Returns a string path from an expression - mostly used to retrieve serialized properties without hardcoding the field path. Safer, and allows for proper refactoring.
Declaration
public static string GetFieldPath<TType, TValue>(Expression<Func<TType, TValue>> expr)
Parameters
| Type | Name | Description |
|---|---|---|
| Expression<Func<TType, TValue>> | expr | Magic expression |
Returns
| Type | Description |
|---|---|
| String | The string version of the field path |
Type Parameters
| Name | Description |
|---|---|
| TType | Magic expression |
| TValue | Magic expression |
GetParentObject(String, Object)
Get the object owner of a field. This method processes the '.' separator to get from the object that owns the compound field to the object that owns the leaf field
Declaration
public static object GetParentObject(string path, object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| String | path | The name of the field, which may contain '.' separators |
| Object | obj | the owner of the compound field |
Returns
| Type | Description |
|---|---|
| Object | The object owner of the field |
GetTypeInAllDependentAssemblies(String)
Get a type from a name
Declaration
public static Type GetTypeInAllDependentAssemblies(string typeName)
Parameters
| Type | Name | Description |
|---|---|---|
| String | typeName | The name of the type to search for |
Returns
| Type | Description |
|---|---|
| Type | The type matching the name, or null if not found |
GetTypesInAllDependentAssemblies(Predicate<Type>)
Search all assemblies for all types that match a predicate
Declaration
public static IEnumerable<Type> GetTypesInAllDependentAssemblies(Predicate<Type> predicate)
Parameters
| Type | Name | Description |
|---|---|---|
| Predicate<Type> | predicate | The type to look for |
Returns
| Type | Description |
|---|---|
| IEnumerable<Type> | A list of types found in the assembly that inherit from the predicate |
GetTypesInAssembly(Assembly, Predicate<Type>)
Search the assembly for all types that match a predicate
Declaration
public static IEnumerable<Type> GetTypesInAssembly(Assembly assembly, Predicate<Type> predicate)
Parameters
| Type | Name | Description |
|---|---|---|
| Assembly | assembly | The assembly to search |
| Predicate<Type> | predicate | The type to look for |
Returns
| Type | Description |
|---|---|
| IEnumerable<Type> | A list of types found in the assembly that inherit from the predicate |