Public Shared Sub GetAttribute(t As Type)
Dim att As DeveloperAttribute
'Get the class-level attributes.
'Put the instance of the attribute on the class level in the att object.
att = CType(Attribute.GetCustomAttribute(t, GetType(DeveloperAttribute)), DeveloperAttribute)
If att Is Nothing Then
Console.WriteLine("No attribute in class {0}.", t.ToString())
Console.WriteLine()
Else
Console.WriteLine("The Name Attribute on the class level is: {0}.", att.Name)
Console.WriteLine("The Level Attribute on the class level is: {0}.", att.Level)
Console.WriteLine("The Reviewed Attribute on the class level is: {0}.", att.Reviewed)
Console.WriteLine()
End If
'Get the method-level attributes.
'Get all methods in this class and put them
'in an array of System.Reflection.MemberInfo objects.
Dim MyMemberInfo As MemberInfo() = t.GetMethods()
'Loop through all methods in this class that are in the
'MyMemberInfo array.
Dim i As Integer
For i = 0 To MyMemberInfo.Length - 1
att = CType(Attribute.GetCustomAttribute(MyMemberInfo(i), GetType(DeveloperAttribute)), DeveloperAttribute)
If att Is Nothing Then
Console.WriteLine("No attribute in member function {0}.", MyMemberInfo(i).ToString())
Console.WriteLine()
Else
Console.WriteLine("The Name Attribute for the {0} member is: {1}.", MyMemberInfo(i).ToString(), att.Name)
Console.WriteLine("The Level Attribute for the {0} member is: {1}.", MyMemberInfo(i).ToString(), att.Level)
Console.WriteLine("The Reviewed Attribute for the {0} member is: {1}.", MyMemberInfo(i).ToString(), att.Reviewed)
Console.WriteLine()
End If
Next i
End Sub