Class ReflectionHelpers
An ad-hoc collection of helpers for reflection, used by Cinemachine or its editor tools in various places
Inheritance
Inherited Members
Namespace: Cinemachine.Utility
Syntax
[DocumentationSorting(DocumentationSortingAttribute.Level.Undoc)]
public static class ReflectionHelpers
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 |
System.Object | obj | The object to access |
System.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 |
CopyFields(Object, Object, BindingFlags)
Copy the fields from one object to another
Declaration
public static void CopyFields(Object src, Object dst, BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
Parameters
Type | Name | Description |
---|---|---|
Object | src | The source object to copy from |
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 |
Returns
Type | Description |
---|---|
System.String |
Type Parameters
Name | Description |
---|---|
TType | |
TValue |
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 |
---|---|---|
System.String | path | The name of the field, which may contain '.' separators |
System.Object | obj | the owner of the compound field |
Returns
Type | Description |
---|---|
System.Object |