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:
  • string fieldName: The name of the field to search

  • SerializedProperty property: 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:
  • string propertyName: The name of the property to search

  • SerializedProperty property: 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:
  • string functionName: The name of the function to search

  • SerializedProperty property: 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:
  • string memberName: The name of the member to look for

  • Type targetType: The type to get the member from

  • BindingFlags bindingFlags: The binding flags

  • MemberTypes memberType: 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:
  • string memberName: The path on which to locate the member

  • MemberTypes memberType: 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:
  • string name: The name of the field to search for

  • Type targetType: The type to get the field from

  • BindingFlags bindingFlags: The binding flags

  • output, FieldInfo fieldInfo: 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:
  • string name: The name of the field to search for

  • Type targetType: The type to get the property from

  • BindingFlags bindingFlags: The binding flags

  • output, PropertyInfo propertyInfo: 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:
  • string name: The name of the field to search for

  • Type targetType: The type to get the function from

  • BindingFlags bindingFlags: The binding flags

  • output, MethodInfo methodInfo: 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:
  • Type type: 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:
  • MemberInfo memberInfo: The member to check

  • params, 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:
  • string memberName: The name of the member to look for

  • SerializedProperty property: 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:
  • SerializedProperty property: The serialized property

  • output, object nestedObject: 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:
  • MemberInfo memberInfo: 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:
  • MemberInfo memberInfo: The member to get the value from

  • SerializedProperty property: The serialized property

  • params, object[] methodParameters: Optional parameter data to pass through if the member is a method

Returns: object: The value of the member