Extensions.SilverlightShared.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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.Common
  10. {
  11. /// <summary>
  12. /// Collection of different extension method specific for Silverlight
  13. /// </summary>
  14. public static partial class Extensions
  15. {
  16. /// <summary>
  17. /// Determines whether [is null or white space] [the specified value].
  18. /// </summary>
  19. /// <param name="value">The value.</param>
  20. /// <returns>
  21. /// <c>true</c> if [is null or white space] [the specified value]; otherwise, <c>false</c>.
  22. /// </returns>
  23. internal static bool IsNullOrWhiteSpace(this string value)
  24. {
  25. if (string.IsNullOrEmpty(value)) return true;
  26. return value.All(char.IsWhiteSpace);
  27. }
  28. /// <summary>
  29. /// Disposes the specified socket.
  30. /// </summary>
  31. /// <param name="socket">The socket.</param>
  32. [DebuggerNonUserCode]
  33. internal static void Dispose(this Socket socket)
  34. {
  35. if (socket == null)
  36. throw new NullReferenceException();
  37. socket.Close();
  38. }
  39. /// <summary>
  40. /// Disposes the specified handle.
  41. /// </summary>
  42. /// <param name="handle">The handle.</param>
  43. [DebuggerNonUserCode]
  44. internal static void Dispose(this WaitHandle handle)
  45. {
  46. if (handle == null)
  47. throw new NullReferenceException();
  48. handle.Close();
  49. }
  50. /// <summary>
  51. /// Disposes the specified algorithm.
  52. /// </summary>
  53. /// <param name="algorithm">The algorithm.</param>
  54. [DebuggerNonUserCode]
  55. internal static void Dispose(this HashAlgorithm algorithm)
  56. {
  57. if (algorithm == null)
  58. throw new NullReferenceException();
  59. algorithm.Clear();
  60. }
  61. }
  62. }