static void Main(string[] args) { Attribute a = Attribute.GetCustomAttribute( typeof(Person), typeof(ProgrammerAttribute)); ProgrammerAttribute p = (ProgrammerAttribute)a; Console.WriteLine("Programmer: {0}", p.Programmer); Console.ReadKey(); }
static void Main(string[] args) { //CTO: GetCustomAttribute tem os mesmos parametros que o IsDefined, ao invez de retornar um booleano ele retorna a referencia do atributo buscado, se nao existir ele retorna null Attribute a = Attribute.GetCustomAttribute( typeof(Person), typeof(ProgrammerAttribute)); ProgrammerAttribute p = (ProgrammerAttribute)a; Console.WriteLine("Programmer: {0}", p.Programmer); Console.ReadKey(); }