Extensions.NET35.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Net.Sockets;
  6. using System.Threading;
  7. using System.Security.Cryptography;
  8. using System.Diagnostics;
  9. namespace Renci.SshNet
  10. {
  11. /// <summary>
  12. /// Collection of different extension method specific for .NET 3.5
  13. /// </summary>
  14. public static partial class Extensions
  15. {
  16. /// <summary>
  17. /// Disposes the specified socket.
  18. /// </summary>
  19. /// <param name="socket">The socket.</param>
  20. [DebuggerNonUserCode]
  21. internal static void Dispose(this Socket socket)
  22. {
  23. if (socket == null)
  24. throw new NullReferenceException();
  25. socket.Close();
  26. }
  27. /// <summary>
  28. /// Disposes the specified handle.
  29. /// </summary>
  30. /// <param name="handle">The handle.</param>
  31. [DebuggerNonUserCode]
  32. internal static void Dispose(this WaitHandle handle)
  33. {
  34. if (handle == null)
  35. throw new NullReferenceException();
  36. handle.Close();
  37. }
  38. /// <summary>
  39. /// Disposes the specified algorithm.
  40. /// </summary>
  41. /// <param name="algorithm">The algorithm.</param>
  42. [DebuggerNonUserCode]
  43. internal static void Dispose(this HashAlgorithm algorithm)
  44. {
  45. if (algorithm == null)
  46. throw new NullReferenceException();
  47. algorithm.Clear();
  48. }
  49. /// <summary>
  50. /// Clears the contents of the string builder.
  51. /// </summary>
  52. /// <param name="value">
  53. /// The <see cref="StringBuilder"/> to clear.
  54. /// </param>
  55. public static void Clear(this StringBuilder value)
  56. {
  57. value.Length = 0;
  58. value.Capacity = 16;
  59. }
  60. }
  61. }