Description
The Clamped
property of the RangeAttribute
class specifies whether the value should be clamped within the defined range. When set to true
, any value assigned to the property will be automatically adjusted to stay within the Min
and Max
bounds defined by the attribute.
Usage
Use the Clamped
property when you want to ensure that a value does not exceed the specified range limits. This is particularly useful in scenarios where you want to prevent invalid data entry or ensure that a value remains within a logical boundary.
Example
// Example of using RangeAttribute with Clamped property
public class ExampleComponent : Component
{
[Range(0, 100, Clamped = true)]
public float Health { get; set; }
public ExampleComponent()
{
Health = 150; // This will be clamped to 100
}
}