Description
The As
property in the SerializedProperty
class provides an accessor to the underlying data of the serialized property. This property is virtual, allowing derived classes to override its behavior if necessary. It is a public instance property, meaning it can be accessed from instances of the SerializedProperty
class or its subclasses.
Usage
Use the As
property when you need to access the underlying data of a serialized property in a type-safe manner. This is particularly useful when working with properties that can hold different types of data, and you need to ensure that you are accessing the data in the correct format.
Example
// Example of accessing the As property
SerializedProperty property = GetSerializedProperty();
var accessor = property.As;
// Use the accessor to interact with the underlying data
// For example, if the property holds an integer value
int value = accessor.GetValue<int>();
accessor.SetValue(42);