daily pastebin goal
57%
SHARE
TWEET

Untitled

a guest Oct 12th, 2017 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [HttpGet]
  2. public void MyResource()
  3. {
  4.     // Controller logic
  5. }
  6.    
  7. public void GetControllerMethodHttpAttribute()
  8. {
  9.     MethodInfo controllerMethod = typeof(TestController).GetMethods().First();
  10.  
  11.     // Solution 1
  12.     var attrs = controllerMethod.Attributes;
  13.  
  14.     // Solution 2
  15.     var httpAttr = Attribute.GetCustomAttributes(typeof(HttpGetAttribute));
  16.  
  17.     // Solution 3
  18.     var httpAttr2 = Attribute.GetCustomAttribute(controllerMethod, typeof(HttpGetAttribute));
  19.  
  20.     // Solution 4
  21.     var httpAttr3 = Attribute.IsDefined(controllerMethod, typeof(HttpGetAttribute));
  22. }
RAW Paste Data
Top