HttpListenerContextAdapter.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Net;
  3. namespace WebDAVSharp.Server.Adapters
  4. {
  5. /// <summary>
  6. /// This
  7. /// <see cref="IHttpListenerContext" /> implementation wraps around a
  8. /// <see cref="HttpListenerContext" /> instance.
  9. /// </summary>
  10. public sealed class HttpListenerContextAdapter : IHttpListenerContext
  11. {
  12. #region Public Functions
  13. /// <summary>
  14. /// Initializes a new instance of the <see cref="HttpListenerContextAdapter" /> class.
  15. /// </summary>
  16. /// <param name="context">The <see cref="HttpListenerContext" /> to adapt for WebDAV#.</param>
  17. /// <exception cref="System.ArgumentNullException">context</exception>
  18. /// <exception cref="ArgumentNullException"><paramref name="context" /> is <c>null</c>.</exception>
  19. public HttpListenerContextAdapter(HttpListenerContext context)
  20. {
  21. if (context == null)
  22. throw new ArgumentNullException(nameof(context));
  23. AdaptedInstance = context;
  24. _request = new HttpListenerRequestAdapter(context.Request);
  25. _response = new HttpListenerResponseAdapter(context.Response);
  26. }
  27. #endregion
  28. #region Private Variables
  29. private readonly HttpListenerRequestAdapter _request;
  30. private readonly HttpListenerResponseAdapter _response;
  31. #endregion
  32. #region Properties
  33. /// <summary>
  34. /// Gets the internal instance that was adapted for WebDAV#.
  35. /// </summary>
  36. /// <value>
  37. /// The adapted instance.
  38. /// </value>
  39. public HttpListenerContext AdaptedInstance { get; }
  40. /// <summary>
  41. /// Gets the <see cref="IHttpListenerRequest" /> request adapter.
  42. /// </summary>
  43. public IHttpListenerRequest Request => _request;
  44. /// <summary>
  45. /// Gets the <see cref="IHttpListenerResponse" /> response adapter.
  46. /// </summary>
  47. public IHttpListenerResponse Response => _response;
  48. #endregion
  49. }
  50. }