[Developer(S"Иван Семенов", S"42", Reviewed = true)]
public__gc class MainApp{
public:
static void GetAttribute(Type* t) {
// Получить атрибут.
DeveloperAttribute* MyAttribute =
__try_cast<DeveloperAttribute*>
(Attribute::GetCustomAttribute(t, __typeof(DeveloperAttribute)));
if (MyAttribute == 0)
Console::WriteLine(S"Атрибут не найден.");
else {
// Получить поле Имя.
Console::WriteLine(S"Имя: {0}." , MyAttribute->Name);
// Получить поле Уровень.
Console::WriteLine(S"Уровень: {0}." , MyAttribute->Level);
// Получить поле Проверено.
Console::WriteLine(S"Проверено: {0}." , MyAttribute->Reviewed);
}
}
};
void main() {
// Вызвать функцию получения и отображения атрибута.
MainApp::GetAttribute(__typeof(MainApp));
}
Visual Basic.NET
Imports System
Class <Developer("Иван Семенов", "42", Reviewed := True)> MainApp
Public Shared Sub Main()
' Вызвать функцию получения и отображения атрибута.
GetAttribute(GetType(MainApp))