Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 30th, 2012  |  syntax: None  |  size: 0.50 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Attribute on method doesn't work
  2. [AttributeUsage(System.AttributeTargets.Method)]
  3. public class RequireAuthorization : System.Attribute
  4. {
  5.     private bool _protected = true;
  6.  
  7.     public RequireAuthorization(bool protect)
  8.     {
  9.         _protected = protect;
  10.     }
  11. }
  12.  
  13. public class MyClass(){
  14.  
  15.     [RequireAuthorization(true)]
  16.     public bool method1(){
  17.        // some actions
  18.     }
  19. }
  20.        
  21. MemberInfo memberInfo = typeof(MyClass).GetMethod("method1");
  22. var attributes = memberInfo.GetCustomAttributes(false);