/// <summary> /// Applies a requirement to the value of the current property. /// If it is not met, when the property's value is set, an exception /// is thrown. /// </summary> /// <param name="condition"></param> /// <param name="failureMessage"></param> /// <returns></returns> public PropertyBase <T> Require(Predicate <T> condition, string failureMessage) { var requirement = new LambdaRequirement <T>(condition, failureMessage, null); AddRequirement(requirement); return(this); }
/// <summary> /// Applies a requirement to the value of the current property. /// If it is not met, when the property's value is set, /// the value is coerced into an acceptable domain. /// </summary> /// <param name="condition"></param> /// <param name="coercion"></param> /// <param name="logMessage"></param> /// <returns></returns> public PropertyBase <T> Coerce(Func <T, T> coercion, string logMessage = "") { if (coercion == null) { throw new ArgumentNullException("coercion"); } //The condition is set to always false, because coercion must //be run in all cases (for every value, even if it is correct). var requirement = new LambdaRequirement <T>(v => false, logMessage, coercion); AddRequirement(requirement); return(this); }