PageRenderTime 41ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/src/NUnit/framework/Constraints/ReusableConstraint.cs

#
C# | 55 lines | 26 code | 7 blank | 22 comment | 0 complexity | 5f9c68b86c4549f5610e9ddafa1eef4a MD5 | raw file
Possible License(s): GPL-2.0
  1. using System;
  2. namespace NUnit.Framework.Constraints
  3. {
  4. /// <summary>
  5. /// ReusableConstraint wraps a resolved constraint so that it
  6. /// may be saved and reused as needed.
  7. /// </summary>
  8. public class ReusableConstraint : IResolveConstraint
  9. {
  10. private Constraint constraint;
  11. /// <summary>
  12. /// Construct a ReusableConstraint
  13. /// </summary>
  14. /// <param name="c">The constraint or expression to be reused</param>
  15. public ReusableConstraint(IResolveConstraint c)
  16. {
  17. this.constraint = c.Resolve();
  18. }
  19. /// <summary>
  20. /// Conversion operator from a normal constraint to a ReusableConstraint.
  21. /// </summary>
  22. /// <param name="c">The original constraint to be wrapped as a ReusableConstraint</param>
  23. /// <returns></returns>
  24. public static implicit operator ReusableConstraint(Constraint c)
  25. {
  26. return new ReusableConstraint(c);
  27. }
  28. /// <summary>
  29. /// Returns the string representation of the constraint.
  30. /// </summary>
  31. /// <returns>A string representing the constraint</returns>
  32. public override string ToString()
  33. {
  34. return constraint.ToString();
  35. }
  36. #region IResolveConstraint Members
  37. /// <summary>
  38. /// Resolves the ReusableConstraint by returning the constraint
  39. /// that it originally wrapped.
  40. /// </summary>
  41. /// <returns>A resolved constraint</returns>
  42. public Constraint Resolve()
  43. {
  44. return constraint;
  45. }
  46. #endregion
  47. }
  48. }