Skip to content

SerializedPropertyExtensions

Namespace: SideXP.Core.EditorOnly

public static class SerializedPropertyExtensions

Extension functions for SerializedProperty instances.

Methods

GetLabel(SerializedProperty)

public static GUIContent GetLabel(SerializedProperty property)

Gets the field label of a serialized property.

Parameters

  • property: The property you want to get the label.

Returns

Returns the label of the given property.

GetTarget(SerializedProperty)

public static object GetTarget(SerializedProperty property)

Gets the target object of this SerializedProperty. This function is inspired by the SpacePuppy Unity Framework: https://github.com/lordofduct/spacepuppy-unity-framework-4.0/blob/master/Framework/com.spacepuppy.core/Editor/src/EditorHelper.cs

Parameters

  • property: The property of which you want to get the target object.

Returns

Returns the found target object.

GetTarget<T>(SerializedProperty)

public static T GetTarget<T>(SerializedProperty property)

Gets the target object of this SerializedProperty. This function is inspired by the SpacePuppy Unity Framework: https://github.com/lordofduct/spacepuppy-unity-framework-4.0/blob/master/Framework/com.spacepuppy.core/Editor/src/EditorHelper.cs

Type parameters

  • T: The expected target type.

Parameters

  • property: The property of which you want to get the target object.

Returns

Returns the found target object.

GetTargetType(SerializedProperty)

public static Type GetTargetType(SerializedProperty property)

Gets the type of a property, using its path.

Parameters

  • property: The property you want to get the type.

Returns

Returns the target type of the property.

Remarks

Note that this function doesn't need the property to be assigned.

TryGetTargetType(SerializedProperty, Type)

public static bool TryGetTargetType(SerializedProperty property, out Type targetType)

Gets the type of a property, using its path.

Parameters

  • targetType: Outputs the target type of the property.
  • property: The property you want to get the type.

Returns

Returns true if the target type has been retrieved successfully.

Remarks

Note that this function doesn't need the property to be assigned.

IsArrayElement(SerializedProperty)

public static bool IsArrayElement(SerializedProperty property)

Checks if the given property is an array element.

Parameters

  • property: The property to check.

Returns

Returns true if the given property is an array element.

Remarks

This can be useful to remove unnecessary labels in the displayed items.