This documentation is archived and is not being maintained.
Defining Your Own Attributes
Using attribute classes, you can create your own custom attributes, and use them in addition to the .NET Framework attributes to provide additional information about program elements.
To define a custom attribute
- Declare a class and apply the AttributeUsage attribute to it. The name of your class is the name of the new attribute, as shown in the following code:
<AttributeUsage(AttributeTargets.All)> Class TestAttribute
- Add an Inherits System.Attribute statement as the first line of code in the class:
- Define Private fields to store property values:
Private m_SomeValue As String
- If appropriate, create a constructor for the attribute:
Public Sub New(ByVal Value As String) m_SomeValue = Value End Sub
- Define methods, fields, and properties for the attribute:
Public Sub Attr(ByVal AttrValue As String) 'Add method code here. End Sub Public Property SomeValue() As String ' A named parameter. Get Return m_SomeValue End Get Set(ByVal Value As String) m_SomeValue = Value End Set End Property
- End the class with the End Class construct: