Route.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace System.Net.ApiService {
  5. public enum HttpMethod:byte {
  6. GET = 1,
  7. PUT = 2,
  8. POST = 4,
  9. DELETE = 8,
  10. PATCH = 16,
  11. TRACE = 32,
  12. OPTIONS = 64,
  13. CONNECT = 128
  14. }
  15. [System.AttributeUsage(System.AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true)]
  16. public class Route : System.Attribute {
  17. private string _path;
  18. private HttpMethod _methode;
  19. //TODO: Regex Pattern for route
  20. public Route(string Path) {
  21. if (!Path.StartsWith("/"))
  22. Path = "/" + Path;
  23. if (Path.EndsWith("/") && Path.Length > 1)
  24. Path = Path.Substring(0, Path.Length - 1);
  25. this._path = Path;
  26. this._methode = HttpMethod.GET | HttpMethod.POST;
  27. }
  28. public Route(string Path, HttpMethod Method) {
  29. this._path = Path;
  30. this._methode = Method;
  31. }
  32. public string Path {
  33. get {
  34. return this._path;
  35. }
  36. }
  37. public HttpMethod Method {
  38. get {
  39. return this._methode;
  40. }
  41. }
  42. }
  43. }