2
0

ExpectAction.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using System.Text.RegularExpressions;
  3. namespace Renci.SshNet
  4. {
  5. /// <summary>
  6. /// Specifies behavior for expected expression.
  7. /// </summary>
  8. public class ExpectAction
  9. {
  10. /// <summary>
  11. /// Gets the expected regular expression.
  12. /// </summary>
  13. public Regex Expect { get; private set; }
  14. /// <summary>
  15. /// Gets the action to perform when expected expression is found.
  16. /// </summary>
  17. public Action<string> Action { get; private set; }
  18. /// <summary>
  19. /// Initializes a new instance of the <see cref="ExpectAction"/> class.
  20. /// </summary>
  21. /// <param name="expect">The expect regular expression.</param>
  22. /// <param name="action">The action to perform.</param>
  23. /// <exception cref="ArgumentNullException"><paramref name="expect"/> or <paramref name="action"/> is <c>null</c>.</exception>
  24. public ExpectAction(Regex expect, Action<string> action)
  25. {
  26. if (expect == null)
  27. {
  28. throw new ArgumentNullException(nameof(expect));
  29. }
  30. if (action == null)
  31. {
  32. throw new ArgumentNullException(nameof(action));
  33. }
  34. Expect = expect;
  35. Action = action;
  36. }
  37. /// <summary>
  38. /// Initializes a new instance of the <see cref="ExpectAction"/> class.
  39. /// </summary>
  40. /// <param name="expect">The expect expression.</param>
  41. /// <param name="action">The action to perform.</param>
  42. /// <exception cref="ArgumentNullException"><paramref name="expect"/> or <paramref name="action"/> is <c>null</c>.</exception>
  43. public ExpectAction(string expect, Action<string> action)
  44. {
  45. if (expect == null)
  46. {
  47. throw new ArgumentNullException(nameof(expect));
  48. }
  49. if (action == null)
  50. {
  51. throw new ArgumentNullException(nameof(action));
  52. }
  53. Expect = new Regex(Regex.Escape(expect));
  54. Action = action;
  55. }
  56. }
  57. }