/// <summary> /// Adds a rule that specifies that the string property must be set and not empty. /// </summary> /// <param name="messageLambda">A lambda or function that will determine the error message to use should this validation rule fail.</param> /// <returns>A <see cref="FluentStringRuleSet{TEntity}"/> object that can be used to chain string rules together.</returns> public FluentStringRuleSet <TEntity> Required(Func <TEntity, string> messageLambda) { var name = String.Format(Resources.FluentIsRequiredName, Property.Name); EntityRules.AddRule(x => !String.IsNullOrEmpty((string)Property.GetValue(x, null)), name, messageLambda); return(this); }
/// <summary> /// Adds a rule that specifies that the string property must be at least a specified length. /// </summary> /// <param name="minimumLength">The minimum length that the string property can be.</param> /// <param name="messageLambda">A lambda or function that will determine the error message to use should this validation rule fail.</param> /// <returns>A <see cref="FluentStringRuleSet{TEntity}"/> object that can be used to chain string rules together.</returns> public FluentStringRuleSet <TEntity> MinimumLength(int minimumLength, Func <TEntity, string> messageLambda) { var name = String.Format(Resources.FluentMinimumLengthName, Property.Name); EntityRules.AddRule(x => ((string)Property.GetValue(x, null)) == null || ((string)Property.GetValue(x, null)).Length >= minimumLength, name, messageLambda); return(this); }
/// <summary> /// Adds a rule that specifies that the string property must match a specific regular expression pattern. /// </summary> /// <param name="pattern">The regular expression pattern that the property must match.</param> /// <param name="messageLambda">A lambda or function that will determine the error message to use should this validation rule fail.</param> /// <returns>A <see cref="FluentStringRuleSet{TEntity}"/> object that can be used to chain string rules together.</returns> public FluentStringRuleSet <TEntity> MatchesPattern(string pattern, Func <TEntity, string> messageLambda) { var name = String.Format(Resources.FluentMatchesPatternName, Property.Name); EntityRules.AddRule(x => ((string)Property.GetValue(x, null)) == null || Regex.IsMatch((string)Property.GetValue(x, null), pattern), name, messageLambda); return(this); }
public FluentNumberRuleSet <TEntity> Minimum(decimal minimum, Func <TEntity, string> messageLambda) { var name = String.Format(Resources.FluentMinimumValueName, Property.Name); EntityRules.AddRule(x => (Property.PropertyType.IsGenericType && Property.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>) ? (Property.GetValue(x, null) != null ? Convert.ToDecimal(Property.GetValue(x, null)) >= minimum : true) : Convert.ToDecimal(Property.GetValue(x, null)) >= minimum), name, messageLambda); return(this); }
/// <summary> /// Adds a rule that specifies that the numeric property must be set. /// </summary> /// <param name="messageLambda">A lambda or function that will determine the error message to use should this validation rule fail.</param> /// <returns>A <see cref="FluentNumberRuleSet{TEntity}"/> object that can be used to chain numeric rules together.</returns> public FluentNumberRuleSet <TEntity> Required(Func <TEntity, string> messageLambda) { var name = String.Format(Resources.FluentIsRequiredName, Property.Name); EntityRules.AddRule(x => Property.PropertyType.IsGenericType && Property.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>) ? ((decimal?)Property.GetValue(x, null)).HasValue : true, name, messageLambda); return(this); }