Guest User

Untitled

a guest
May 22nd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. public override void Close()
  2. {
  3. this.Dispose(true);
  4. GC.SuppressFinalize(this);
  5. }
  6.  
  7. public void Dispose()
  8. {
  9. this.Dispose(true);
  10. GC.SuppressFinalize(this);
  11. }
  12.  
  13. /// <summary>
  14. /// Encapsulates a stream writer which does not close the underlying stream.
  15. /// </summary>
  16. public class NoCloseStreamWriter : StreamWriter
  17. {
  18. /// <summary>
  19. /// Creates a new stream writer object.
  20. /// </summary>
  21. /// <param name="stream">The underlying stream to write to.</param>
  22. /// <param name="encoding">The encoding for the stream.</param>
  23. public NoCloseStreamWriter(Stream stream, Encoding encoding)
  24. : base(stream, encoding)
  25. {
  26. }
  27.  
  28. /// <summary>
  29. /// Creates a new stream writer object using default encoding.
  30. /// </summary>
  31. /// <param name="stream">The underlying stream to write to.</param>
  32. /// <param name="encoding">The encoding for the stream.</param>
  33. public NoCloseStreamWriter(Stream stream)
  34. : base(stream)
  35. {
  36. }
  37.  
  38. /// <summary>
  39. /// Disposes of the stream writer.
  40. /// </summary>
  41. /// <param name="disposing">True to dispose managed objects.</param>
  42. protected override void Dispose(bool disposeManaged)
  43. {
  44. // Dispose the stream writer but pass false to the dispose
  45. // method to stop it from closing the underlying stream
  46. base.Dispose(false);
  47. }
  48. }
Add Comment
Please, Sign In to add comment