/// <summary> /// Initializes a new instance of the EZNEW.Develop.DataValidation.ValidationItem<> class /// </summary> /// <param name="field">Field</param> /// <param name="validator">Data validator</param> /// <param name="fieldName">Field name</param> public ValidationItem(ValidationField <T> field, DataValidator validator, string fieldName) { valueMethod = field.Field.Compile(); this.validator = validator; this.fieldName = fieldName; errorMessage = field.ErrorMessage; if (field.CompareValue is Expression <Func <T, dynamic> > compareExpress) { comparePropertyName = ExpressionHelper.GetExpressionText(compareExpress); compareValue = compareExpress.Compile(); } else { compareValue = field.CompareValue; } }
/// <summary> /// Greaterthan or equal /// </summary> /// <typeparam name="T">Data type</typeparam> /// <param name="value">Value</param> /// <param name="field">Field</param> public static void GreaterThanOrEqual <T>(Expression <Func <T, dynamic> > value, ValidationField <T> field) { SetCompareValidation(CompareOperator.GreaterThanOrEqual, value, field); }
/// <summary> /// Not in /// </summary> /// <typeparam name="T">Data type</typeparam> /// <param name="value">Value</param> /// <param name="field">Field</param> public static void NotIn <T>(IEnumerable <dynamic> value, ValidationField <T> field) { SetCompareValidation(CompareOperator.NotIn, value, field); }
/// <summary> /// Greaterthan or equal /// </summary> /// <typeparam name="T">Data type</typeparam> /// <param name="value">Value</param> /// <param name="field">Field</param> public static void GreaterThanOrEqual <T>(dynamic value, ValidationField <T> field) { SetCompareValidation(CompareOperator.GreaterThanOrEqual, value, field); }
/// <summary> /// Lessthan /// </summary> /// <typeparam name="T">Data type</typeparam> /// <param name="value">Value</param> /// <param name="field">Field</param> public static void LessThan <T>(Expression <Func <T, dynamic> > value, ValidationField <T> field) { SetCompareValidation(CompareOperator.LessThan, value, field); }
/// <summary> /// Lessthan /// </summary> /// <typeparam name="T">Data type</typeparam> /// <param name="value">Value</param> /// <param name="field">Field</param> public static void LessThan <T>(dynamic value, ValidationField <T> field) { SetCompareValidation(CompareOperator.LessThan, value, field); }
/// <summary> /// Not equal /// </summary> /// <typeparam name="T">Data type</typeparam> /// <param name="value">Value</param> /// <param name="field">Field</param> public static void NotEqual <T>(dynamic value, ValidationField <T> field) { SetCompareValidation(CompareOperator.NotEqual, value, field); }
/// <summary> /// Set compare validation /// </summary> /// <typeparam name="T">Data type</typeparam> /// <param name="compareOperator">Compare operator</param> /// <param name="value">Value</param> /// <param name="field">Field</param> public static void SetCompareValidation <T>(CompareOperator compareOperator, dynamic value, ValidationField <T> field) { string validatorKey = string.Format("{0}/{1}", typeof(CompareValidator).FullName, (int)compareOperator); DataValidator validator; if (Validators.ContainsKey(validatorKey)) { validator = Validators[validatorKey]; } else { validator = new CompareValidator(compareOperator); Validators.Add(validatorKey, validator); } field.CompareValue = value; SetValidation(validator, field); }