To get information on attributes at the program runtime, use properties and methods of the System.Attribute class. This class is described in MSDN.
Imports System;
Imports System.Reflection;
Imports System.Diagnostics;
Sub ExtractAttributeInfo();
Var
Obj: TestAttribute = New TestAttribute();
ObjType, UserAttrType: System.Type;
ObjMethodInfo: MethodInfo;
Attr: System.Attribute;
Begin
//Get object type
ObjType := Obj.GetType();
//Get attribute class type
UserAttrType := (New UserAttribute(UserStatus.None)).GetType();
//Get list of class methods
For Each ObjMethodInfo In ObjType.GetMethods() Do
//Get data on attributes of each class method
For Each Attr In Attribute.GetCustomAttributes(ObjMethodInfo) Do
If Attr.GetType() = UserAttrType Then
Debug.Write((Attr As UserAttribute).Status);
Debug.WriteLine(" " + (Attr As UserAttribute).AdditionalValue);
End If;
End For;
End For;
End Sub;
This example creates an instance of the TestAttribute object, which code is given in description of attribute parameters. Attributes are determined for the methods. Values of attribute parameters are displayed in the development environment console.
See also: