/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
- using System;
-
- namespace NUnit.Framework.Constraints
- {
- /// <summary>
- /// ReusableConstraint wraps a resolved constraint so that it
- /// may be saved and reused as needed.
- /// </summary>
- public class ReusableConstraint : IResolveConstraint
- {
- private Constraint constraint;
-
- /// <summary>
- /// Construct a ReusableConstraint
- /// </summary>
- /// <param name="c">The constraint or expression to be reused</param>
- public ReusableConstraint(IResolveConstraint c)
- {
- this.constraint = c.Resolve();
- }
-
- /// <summary>
- /// Conversion operator from a normal constraint to a ReusableConstraint.
- /// </summary>
- /// <param name="c">The original constraint to be wrapped as a ReusableConstraint</param>
- /// <returns></returns>
- public static implicit operator ReusableConstraint(Constraint c)
- {
- return new ReusableConstraint(c);
- }
-
- /// <summary>
- /// Returns the string representation of the constraint.
- /// </summary>
- /// <returns>A string representing the constraint</returns>
- public override string ToString()
- {
- return constraint.ToString();
- }
-
- #region IResolveConstraint Members
-
- /// <summary>
- /// Resolves the ReusableConstraint by returning the constraint
- /// that it originally wrapped.
- /// </summary>
- /// <returns>A resolved constraint</returns>
- public Constraint Resolve()
- {
- return constraint;
- }
-
- #endregion
- }
- }