private void CreateValidationsForField(DynamicValidationProperty property) { var propertyExpression = _linqExpressionService.GetParameterExpression(typeof(T), property.PropertyName); if (!property.AllowNullOrEmpty) { RuleFor(propertyExpression).NotNull().NotEmpty(); } foreach (var validationCriteria in property.ValidationCriterias) { switch (validationCriteria.CriteriaType) { case CriteriaTypeEnum.NotNull: RuleFor(propertyExpression).NotNull(); break; case CriteriaTypeEnum.NotEmpty: RuleFor(propertyExpression).NotEmpty(); break; case CriteriaTypeEnum.NotNullOrEmpty: RuleFor(propertyExpression).NotNull().NotEmpty(); break; case CriteriaTypeEnum.Equal: RuleFor(propertyExpression).Equal(validationCriteria.Value); break; case CriteriaTypeEnum.NotEqual: RuleFor(propertyExpression).NotEqual(validationCriteria.Value); break; default: throw new Exception("Invalid CriteriaType"); } } if (propertyExpression.Type == typeof(string)) { Expression <Func <T, string> > stringExpression = ExpressionTostringExpression(propertyExpression); CreateValidationsForString(stringExpression, property.ValidationCriterias); } if (propertyExpression.Type == typeof(int)) { Expression <Func <T, int> > intExpression = ExpressionToIntExpression(propertyExpression); CreateValidationsForInt(intExpression, property.ValidationCriterias); } }
private void CreateValidationsForList(DynamicValidationProperty property) { throw new NotImplementedException(); }