ReflectionUtils
An utility class containing usefull functions related to reflection.
- Inheritance:
object -> ReflectionUtils
- Namespace:
EditorAttributes.Editor.Utility
- Assembly:
EditorAttributes.Editor.asmdef
Syntax:
public static class ReflectionUtils
Fields
BINDING_FLAGS
A preset of binding flags used by the package.
Type: BindingFlags
Declaration:
public const BindingFlags BINDING_FLAGS;
Methods
FindField(string, SerializedProperty)
Finds a field inside a serialized object.
Declaration:
public static FieldInfo FindField(string fieldName, SerializedProperty property)
- Parameters:
stringfieldName: The name of the field to searchSerializedPropertyproperty: The serialized property
Returns: FieldInfo: The field info of the desired field
FindProperty(string, SerializedProperty)
Finds a property inside a serialized object.
Declaration:
public static PropertyInfo FindProperty(string propertyName, SerializedProperty property)
- Parameters:
stringpropertyName: The name of the property to searchSerializedPropertyproperty: The serialized property
Returns: PropertyInfo: The property info of the desired property
FindFunction(string, SerializedProperty)
Finds a funciton inside a serialized object.
Declaration:
public static MethodInfo FindFunction(string functionName, SerializedProperty property)
- Parameters:
stringfunctionName: The name of the function to searchSerializedPropertyproperty: The serialized property
Returns: MethodInfo: The field info of the desired field
FindMember(string, Type, BindingFlags, MemberTypes)
Finds a member from the target type and it’s inherited types.
Declaration:
public static MemberInfo FindMember(string memberName, Type targetType, BindingFlags bindingFlags, MemberTypes memberType)
- Parameters:
stringmemberName: The name of the member to look forTypetargetType: The type to get the member fromBindingFlagsbindingFlags: The binding flagsMemberTypesmemberType: The type of the member to look for. Only Field, Property and Method types are supported
Returns: MemberInfo: The member info of the specified member type
GetStaticMemberInfoFromPath(string, MemberTypes)
Gets the info of a const or static member from the type specified in the path.
Declaration:
public static MemberInfo FindMember(string memberName, Type targetType, BindingFlags bindingFlags, MemberTypes memberType)
- Parameters:
stringmemberName: The path on which to locate the memberMemberTypesmemberType: The type of the member to look for. Only Field, Property and Method types are supported
Returns: MemberInfo: The member info of the specified member type
TryGetField(string, Type, BindingFlags, out FieldInfo)
Tries to get a field from the target type.
Declaration:
public static bool TryGetField(string name, Type targetType, BindingFlags bindingFlags, out FieldInfo fieldInfo)
- Parameters:
stringname: The name of the field to search forTypetargetType: The type to get the field fromBindingFlagsbindingFlags: The binding flagsoutput,
FieldInfofieldInfo: The field info of the desired field
Returns: bool: True if the field was succesfully found, false otherwise
TryGetProperty(string, Type, BindingFlags, out PropertyInfo)
Tries to get a property from the target type.
Declaration:
public static bool TryGetProperty(string name, Type targetType, BindingFlags bindingFlags, out PropertyInfo propertyInfo)
- Parameters:
stringname: The name of the field to search forTypetargetType: The type to get the property fromBindingFlagsbindingFlags: The binding flagsoutput,
PropertyInfopropertyInfo: The property info of the desired field
Returns: bool: True if the field was succesfully found, false otherwise
TryGetMethod(string, Type, BindingFlags, out MethodInfo)
Tries to get a function from the target type.
Declaration:
public static bool TryGetMethod(string name, Type targetType, BindingFlags bindingFlags, out MethodInfo methodInfo)
- Parameters:
stringname: The name of the field to search forTypetargetType: The type to get the function fromBindingFlagsbindingFlags: The binding flagsoutput,
MethodInfomethodInfo: The method info of the desired field
Returns: bool: True if the field was succesfully found, false otherwise
IsTypeCollection(Type)
Checks to see if a type is a list or array.
Declaration:
public static bool IsTypeCollection(Type type)
- Parameters:
Typetype: The type to check
Returns: bool: True if the type is a list or array
HasAnyAttributes(MemberInfo, params Type[])
Checks to see if a member has one of the specified attributes.
Declaration:
public static bool HasAnyAttributes(MemberInfo memberInfo, params Type[] attributeTypes)
- Parameters:
MemberInfomemberInfo: The member to checkparams,
Type[]attributeTypes: The attribute types
Returns: bool: True if the member has at least one of specified attributes
GetValidMemberInfo(string, SerializedProperty)
Finds a member inside a serialzied object.
Declaration:
public static MemberInfo GetValidMemberInfo(string memberName, SerializedProperty serializedProperty)
- Parameters:
stringmemberName: The name of the member to look forSerializedPropertyproperty: The serialized property
Returns: MemberInfo: The member info of the member
GetNestedObjectType(SerializedProperty, out object)
Gets the type of a nested serialized object.
Declaration:
public static Type GetNestedObjectType(SerializedProperty property, out object nestedObject)
- Parameters:
SerializedPropertyproperty: The serialized propertyoutput,
objectnestedObject: Outputs the serialized nested object
Returns: Type: The nested object type
GetMemberInfoType(MemberInfo)
Gets the type of a member.
Declaration:
public static Type GetMemberInfoType(MemberInfo memberInfo)
- Parameters:
MemberInfomemberInfo: The member to get the type from
Returns: Type: The type of the member
GetMemberInfoValue(MemberInfo, SerializedProperty, params object[])
Gets the value of a member.
Declaration:
public static object GetMemberInfoValue(MemberInfo memberInfo, SerializedProperty property, params object[] methodParameters)
- Parameters:
MemberInfomemberInfo: The member to get the value fromSerializedPropertyproperty: The serialized propertyparams,
object[]methodParameters: Optional parameter data to pass through if the member is a method
Returns: object: The value of the member