PageRenderTime 28ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/WCFWebApi/src/Microsoft.Net.Http.Formatting/System/Net/Http/MultipartMemoryStreamProvider.cs

#
C# | 53 lines | 27 code | 6 blank | 20 comment | 2 complexity | 8a3daed375aaaa740a666f6c39e0d045 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, Apache-2.0
  1. // <copyright>
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. // </copyright>
  4. namespace System.Net.Http
  5. {
  6. using System.IO;
  7. using System.Net.Http.Headers;
  8. /// <summary>
  9. /// Provides a <see cref="IMultipartStreamProvider"/> implementation that returns a <see cref="MemoryStream"/> instance.
  10. /// This facilitates deserialization or other manipulation of the contents in memory.
  11. /// </summary>
  12. internal class MultipartMemoryStreamProvider : IMultipartStreamProvider
  13. {
  14. private static MultipartMemoryStreamProvider instance = new MultipartMemoryStreamProvider();
  15. private MultipartMemoryStreamProvider()
  16. {
  17. }
  18. /// <summary>
  19. /// Gets a static instance of the <see cref="MultipartMemoryStreamProvider"/>
  20. /// </summary>
  21. public static MultipartMemoryStreamProvider Instance
  22. {
  23. get
  24. {
  25. return MultipartMemoryStreamProvider.instance;
  26. }
  27. }
  28. /// <summary>
  29. /// This <see cref="IMultipartStreamProvider"/> implementation returns a <see cref="MemoryStream"/> instance.
  30. /// This facilitates deserialization or other manipulation of the contents in memory.
  31. /// </summary>
  32. /// <param name="headers">The header fields describing the body parts content. Looking for header fields such as
  33. /// Content-Type and Content-Disposition can help provide the appropriate stream. In addition to using the information
  34. /// in the provided header fields, it is also possible to add new header fields or modify existing header fields. This can
  35. /// be useful to get around situations where the Content-type may say <b>application/octet-stream</b> but based on
  36. /// analyzing the <b>Content-Disposition</b> header field it is found that the content in fact is <b>application/json</b>, for example.</param>
  37. /// <returns>A stream instance where the contents of a body part will be written to.</returns>
  38. public Stream GetStream(HttpContentHeaders headers)
  39. {
  40. if (headers == null)
  41. {
  42. throw new ArgumentNullException("headers");
  43. }
  44. return new MemoryStream();
  45. }
  46. }
  47. }