Use the GetCustomAttributes method : Attributes Reflection : Attribute C# Examples


C# Examples » Attribute » Attributes Reflection »

 

Use the GetCustomAttributes method









    
using  System;

public  class  TrueFalseAttribute  :  Attribute
{
    bool  bWritten;

    public  bool  Written()
    {
        return  bWritten;
    }

    public  TrueFalseAttribute(bool  Written)
    {
        bWritten  =  Written;
    }
}

public  class  StringAttribute  :  Attribute
{
    string  sStage;

    public  string  Stage()
    {
        return  sStage;
    }

    public  StringAttribute(string  Stage)
    {
        sStage  =  Stage;
    }
}

[TrueFalseAttribute(true)]
[StringAttribute("Coding")]
public  class  Class1
{
}

class  MainClass
{
    public  static  void  Main()  
    {
        Console.WriteLine("Class1  attributes:  ");object[]  aAttributes  =  Attribute.GetCustomAttributes(typeof(Class1));
        foreach  (object  attr  in  aAttributes)
        {
            Console.WriteLine(attr);
        }
    }
}
    
   
  
   



Output

Class1 attributes:
StringAttribute
TrueFalseAttribute


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Attribute
» Attributes Reflection