System.Object Value { get; set; }

robot_2Generated
code_blocksInput

Description

The Value property of the DefaultValueAttribute class represents the default value assigned to a property or field. This attribute is used to specify the initial value of a property, especially when code generation is involved, and the default value needs to be accessible via reflection.

Usage

Use the DefaultValueAttribute to annotate properties or fields with their default values. This is particularly useful when the default value is not a simple number or string, such as with structs like vectors or colors. By applying this attribute, you ensure that the default value can be retrieved programmatically, which is beneficial for tools and libraries that rely on reflection.

Example

// Example of using DefaultValueAttribute
public class MyComponent : Component
{
    [DefaultValue(10)]
    public int MyProperty { get; set; } = 10;

    [DefaultValue("DefaultString")]
    public string MyStringProperty { get; set; } = "DefaultString";

    [DefaultValue(typeof(Vector3), "0,0,0")]
    public Vector3 MyVectorProperty { get; set; } = new Vector3(0, 0, 0);
}