Attribute Parameters

Position and Named Parameters

Attribute classes may have position and named parameters. Each open instance constructor of a class determines an available sequence of position parameters for a given attribute class. Each open instance property available for reading and writing determines a named parameter for a given attribute class.

Values of position parameters are specified in the order they were declared in the corresponding constructor. Position parameters are mandatory.

Values of named parameters are specified as <Parameter name> := <value>. Named parameters are specified after all position parameters; they are optional.

Types of Attribute Parameters

Attribute classes may have only the following types of attribute parameters:

Example

Below is an example of determining a custom attribute class. Two parameters are specified for the attribute. Parameter values are stored in the Status and AdditionalValue properties. The TestAttribute class determines a custom attribute with various values of parameters for the methods.

Public Enum UserStatus
    None, User, Admin, ISA
End Enum UserStatus;

//Attribute class
Public Class UserAttribute: System.Attribute
    User: UserStatus;
    s: String;

    Public Constructor UserAttribute(Status: UserStatus);
    Begin
        User := Status;
    End Constructor;

    Public Property Status: UserStatus
        Get
        Begin
            Return User
        End Get
        Set
        Begin
            User := Status;
        End Set
    End Property;

    Public Property AdditionalValue: String
        Get
        Begin
            Return s
        End Get
        Set
        Begin
            s := Value;
        End Set
    End Property;
End Class UserAttribute;

Public Class TestAttribute

    //Attribute with position parameter
    [User(UserStatus.User)]
    Public Sub UserMethod();
    Begin
        
    End Sub;

    //Attribute with position and named parameter
    [User(UserStatus.Admin, AdditionalValue := "1")]
    Public Sub AdminMethod();
    Begin
        
    End Sub;

    [User(UserStatus.ISA, AdditionalValue := "2")]
    Public Sub ISAMethod();
    Begin
        
    End Sub;

End Class;

See also:

Attributes