Advertisement
Guest User

Untitled

a guest
Oct 12th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement