private void RegisterValidationRuleGenerator() { //TODO: make this type non static and Ioc with singelton lifetime will be used instead CustomAttrValidationRegistrator.Register(new RequiredConditionRuleGenerator()); CustomAttrValidationRegistrator.Register(new StringLengthConditionRuleGenerator()); CustomAttrValidationRegistrator.Register(new EmailOrRFPhoneRuleGenerator()); }
private string BuildAttributeBasedValidation(List <ValidationAttribute> attributes, string propertyName) { var result = new StringBuilder(); foreach (var attribute in attributes) { #region Custom attributes(will be removed from here, custom attributes will be applied with registration on app start.) //generation for custom registered validation attributes //TODO(Alex) : serviceLocator to be used here if (CustomAttrValidationRegistrator.IsRegistered(attribute)) { result.Append(CustomAttrValidationRegistrator.GenerateRuleIfRegistered(attribute, propertyName)); continue; } #endregion if (attribute is StringLengthAttribute) { result.Append(BuildValidationWithLengthAttribute(attribute as StringLengthAttribute, propertyName)); continue; } if (attribute is PhoneAttribute) { //result.Append(BuildValidationWithPhoneAttribute(attribute as PhoneAttribute, propertyName)); continue; } if (attribute is RequiredAttribute) { result.Append(BuildValidationWithRequiredAttribute(attribute as RequiredAttribute, propertyName)); continue; } if (attribute is MinLengthAttribute) { result.Append(BuildValidationWithMinLengthAttribute(attribute as MinLengthAttribute, propertyName)); continue; } if (attribute is MaxLengthAttribute) { result.Append(BuildValidationWithMaxLengthAttribute(attribute as MaxLengthAttribute, propertyName)); continue; } if (attribute is EmailAddressAttribute) { result.Append(BuildValidationWithEmailLengthAttribute(attribute as EmailAddressAttribute, propertyName)); continue; } if (attribute is RegularExpressionAttribute) { result.Append(BuildValidationWithMaxLengthAttribute(attribute as RegularExpressionAttribute, propertyName)); } } result = FormatString(result); return(result.ToString()); }