Friday, 4 May 2012

How to passing array to custome attribute constructor

 

 

void Main()

{

       testing t = new testing();

       t.method12();

      

}

 

// Define other methods and classes here

 

public class testing

{

 

[Author("hello" , Company.ow , Company.FC )]

[Author("farzad")]

[Author("Matthew")]

[Author( Company.bw , Company.NF )]

public void  method12()

       {

       StackTrace st = new StackTrace ();

       StackFrame sf = st.GetFrame (0);

 

       MethodBase currentMethodName = sf.GetMethod ();

 

       currentMethodName.Dump();

       var CustomAttributes =  currentMethodName.GetCustomAttributes(false);

       var CustomAttributesData =  currentMethodName.GetCustomAttributesData();

      

       CustomAttributes.Dump();

       CustomAttributesData.Dump();

       }

 

}

 

[System.AttributeUsage(System.AttributeTargets.Class |

                                     System.AttributeTargets.Method ,

                                     AllowMultiple = true// multiuse attribute

]

public class Author : System.Attribute

{

       public Author(string name , params  Company[] companies)

       {

              Name=name ;

              CompanyList=companies ;

       }

 

public Author(params  Company[] companies)

       {

              CompanyList=companies ;

       }

      

public Author( string name)

       {

              Name=name ;

       }

 

       public Company[] CompanyList { get; set; }

       public string Name { get; set; }

}

 

public enum Company

{

bw,

ow,

CI,

FC,

NF,

}

 



Poupart Group
Poupart Limited is a company registered in England & Wales with the registration number 0310358. The registered address is 5th Floor, 9 Hatton Street, London, NW8 9PL.


This message is confidential. It may also be privileged or otherwise protected by work product immunity or other legal rules.

If you have received it by mistake, please let us know by e-mail reply and delete it from your system; you may not copy this message or disclose its contents to anyone.

Please send us by fax any message containing deadlines as incoming e-mails are not screened for response deadlines.

The integrity and security of this message cannot be guaranteed on the internet.

No comments:

Post a Comment