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