Ejemplo n.º 1
0
        /// <summary>
        /// Add a property validator for the given property with validation rules.
        /// </summary>
        /// <param name="getterExpression">Expression for the targeted property.</param>
        /// <param name="validationRules">Delegate to add validation rules. Action may N validation rules.</param>
        /// <param name="overrideFieldName">To override field Name. By default uses the name of property.</param>
        /// <returns>current instance.</returns>
        public ClassValidator <TRow> For(Expression <Func <TRow, string> > getterExpression, Action <IPropertyValidatorAction <TRow> > validationRules, string overrideFieldName = null)
        {
            var prop = PropertyValidator <TRow> .For(getterExpression, overrideFieldName);

            validationRules(prop);
            this.listValidator.Add(prop);
            return(this);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Add a property validator for the given property with validation rules.
        /// </summary>
        /// <param name="getter">delegate for the targeted property.</param>
        /// <param name="fieldName">To override field Name. By default uses the name of property.</param>
        /// <param name="validationRules">Delegate to add validation rules. Action may N validation rules.</param>
        /// <returns>current instance.</returns>
        public ClassDynamicValidator For(Func <dynamic, string> getter, string fieldName, Action <IPropertyValidatorAction <dynamic> > validationRules)
        {
            var prop = PropertyValidator <dynamic> .ForDynamic(getter, fieldName);

            validationRules(prop);
            this.AddPropertyValidator(prop);
            return(this);
        }
        /// <summary>
        /// Creates a property validator for a dynamic property.
        /// </summary>
        /// <param name="getter">The targeted dynamic property.</param>
        /// <param name="fieldName">Fieldname for the dynamic property.</param>
        /// <returns>A property validator.</returns>
        public static PropertyValidator <dynamic> ForDynamic(Func <dynamic, string> getter, string fieldName)
        {
            PropertyValidator <dynamic> prop = new PropertyValidator <dynamic>();

            prop.getter    = getter;
            prop.fieldName = fieldName;
            return(prop);
        }
        /// <summary>
        /// Creates a property validator for the given property.
        /// </summary>
        /// <param name="propertyExpression">Expression for the targeted property.</param>
        /// <param name="getterExpression">Expression for the getter (if different from property).</param>
        /// <param name="overrideFieldName">To override field Name. By default uses the name of property.</param>
        /// <returns>A property validator.</returns>
        public static PropertyValidator <TRow> For(Expression <Func <TRow, string> > propertyExpression, Expression <Func <TRow, string> > getterExpression, string overrideFieldName = null)
        {
            PropertyValidator <TRow> prop = new PropertyValidator <TRow>();

            prop.getter           = getterExpression.Compile();
            prop.getterExpression = getterExpression;
            prop.fieldName        = overrideFieldName ?? ExpressionUtiities.PropertyName(propertyExpression);
            return(prop);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Add a property validator. <see cref="PropertyValidator{TRow}"/>.
 /// </summary>
 /// <param name="propValidator">Targeted property validator.</param>
 /// <returns>current instance.</returns>
 public ClassValidator <TRow> AddProperty(PropertyValidator <TRow> propValidator)
 {
     this.listValidator.Add(propValidator);
     return(this);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Allow inherited classes to add property Validator.
 /// </summary>
 /// <param name="property">a property validator.</param>
 protected void AddPropertyValidator(PropertyValidator <TRow> property)
 {
     this.listValidator.Add(property);
 }