public static BaseConstraintGenerator Create(BaseFieldGenerator field, ValidationRule rule) { if (rule is LengthConstraint) return new LengthConstraintGenerator(field, (LengthConstraint)rule); if (rule is RangeConstraint) return new RangeConstraintGenerator(field, (RangeConstraint)rule); if (rule is MatchConstraint) return new MatchConstraintGenerator(field, (MatchConstraint)rule); if (rule is PredefinedValue) return new ListConstraintGenerator(field, (PredefinedValue)rule); if (rule is CodedConstraint) return new CodeConstraintGenerator(field, (CodedConstraint) rule); throw new ApplicationException("Invalid constraint type " + rule.GetType()); }
private static ValidationParseException ConstructionException(ValidationRule rule) => new ValidationParseException($"Error converting rule from {rule.GetType()} to {typeof(ValidationAttribute)}. \r\n" + $"Rule: {rule.Model}.{rule.Property}.{rule.RuleType}");