using System;
namespace Recetas.Cap03
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Assembly,
AllowMultiple = true, Inherited = false)]
public class AutorAttribute : Attribute
{
private string organizacion;
private string nombre;
// Constructor público:
public AutorAttribute (string nombre)
{
this.nombre = nombre;
organizacion = String.Empty;
}
// Accede y modifica el nombre de la organización:
public string Organizacion
{
get
{
return organizacion;
}
set
{
organizacion = value;
}
}
// Propiedad de sólo lectura (campo opcional):
public string Nombre
{
get
{
return nombre;
}
}
}
[AutorAttribute("Edward")]
[AutorAttribute("Germán", Organizacion = "OrtizOL")]
public class Reporte { }
public sealed class ConsultaAutorAttribute
{
public static void Main()
{
// Obtención del tipo:
Type tipo = typeof (Reporte);
// Recuperación arreglo con los atributos aplicados a `Reporte`:
object[] atributos = tipo.GetCustomAttributes(typeof(AutorAttribute), true);
// Enumera los atributos aplicados a `Reporte`:
foreach (AutorAttribute atributo in atributos)
{
Console.WriteLine ("Nombre: {0} - Organización: {1}", atributo.Nombre, atributo.Organizacion);
}
}
}
}
dXNpbmcgU3lzdGVtOwoKbmFtZXNwYWNlIFJlY2V0YXMuQ2FwMDMKewogICAgW0F0dHJpYnV0ZVVzYWdlKEF0dHJpYnV0ZVRhcmdldHMuQ2xhc3MgfCBBdHRyaWJ1dGVUYXJnZXRzLkFzc2VtYmx5LAogICAgICAgICAgICAgICAgQWxsb3dNdWx0aXBsZSA9IHRydWUsIEluaGVyaXRlZCA9IGZhbHNlKV0KICAgIHB1YmxpYyBjbGFzcyBBdXRvckF0dHJpYnV0ZSA6IEF0dHJpYnV0ZQogICAgewogICAgICAgIHByaXZhdGUgc3RyaW5nIG9yZ2FuaXphY2lvbjsKICAgICAgICBwcml2YXRlIHN0cmluZyBub21icmU7CiAgICAgICAgCiAgICAgICAgLy8gQ29uc3RydWN0b3IgcMO6YmxpY286CiAgICAgICAgcHVibGljIEF1dG9yQXR0cmlidXRlIChzdHJpbmcgbm9tYnJlKQogICAgICAgIHsKICAgICAgICAgICAgdGhpcy5ub21icmUgPSBub21icmU7CiAgICAgICAgICAgIG9yZ2FuaXphY2lvbiA9IFN0cmluZy5FbXB0eTsKICAgICAgICB9CiAgICAgICAgCiAgICAgICAgLy8gQWNjZWRlIHkgbW9kaWZpY2EgZWwgbm9tYnJlIGRlIGxhIG9yZ2FuaXphY2nDs246CiAgICAgICAgcHVibGljIHN0cmluZyBPcmdhbml6YWNpb24KICAgICAgICB7CiAgICAgICAgICAgIGdldAogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICByZXR1cm4gb3JnYW5pemFjaW9uOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHNldAogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBvcmdhbml6YWNpb24gPSB2YWx1ZTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICAKICAgICAgICAvLyBQcm9waWVkYWQgZGUgc8OzbG8gbGVjdHVyYSAoY2FtcG8gb3BjaW9uYWwpOgogICAgICAgIHB1YmxpYyBzdHJpbmcgTm9tYnJlCiAgICAgICAgewogICAgICAgICAgICBnZXQKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgcmV0dXJuIG5vbWJyZTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KICAgIAogICAgW0F1dG9yQXR0cmlidXRlKCJFZHdhcmQiKV0KICAgIFtBdXRvckF0dHJpYnV0ZSgiR2VybcOhbiIsIE9yZ2FuaXphY2lvbiA9ICJPcnRpek9MIildCiAgICBwdWJsaWMgY2xhc3MgUmVwb3J0ZSB7IH0KICAgIAogICAgcHVibGljIHNlYWxlZCBjbGFzcyBDb25zdWx0YUF1dG9yQXR0cmlidXRlCiAgICB7CiAgICAgICAgcHVibGljIHN0YXRpYyB2b2lkIE1haW4oKQogICAgICAgIHsKICAgICAgICAgICAgLy8gT2J0ZW5jacOzbiBkZWwgdGlwbzoKICAgICAgICAgICAgVHlwZSB0aXBvID0gdHlwZW9mIChSZXBvcnRlKTsKICAgICAgICAgICAgCiAgICAgICAgICAgIC8vIFJlY3VwZXJhY2nDs24gYXJyZWdsbyBjb24gbG9zIGF0cmlidXRvcyBhcGxpY2Fkb3MgYSBgUmVwb3J0ZWA6CiAgICAgICAgICAgIG9iamVjdFtdIGF0cmlidXRvcyA9IHRpcG8uR2V0Q3VzdG9tQXR0cmlidXRlcyh0eXBlb2YoQXV0b3JBdHRyaWJ1dGUpLCB0cnVlKTsKICAgICAgICAgICAgCiAgICAgICAgICAgIC8vIEVudW1lcmEgbG9zIGF0cmlidXRvcyBhcGxpY2Fkb3MgYSBgUmVwb3J0ZWA6CiAgICAgICAgICAgIGZvcmVhY2ggKEF1dG9yQXR0cmlidXRlIGF0cmlidXRvIGluIGF0cmlidXRvcykKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUgKCJOb21icmU6IHswfSAtIE9yZ2FuaXphY2nDs246IHsxfSIsIGF0cmlidXRvLk5vbWJyZSwgYXRyaWJ1dG8uT3JnYW5pemFjaW9uKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KfQ==