@ -33,47 +33,51 @@ public abstract class ExtensionPropertyComponentBase<TEntity, TResourceType> : O
{
e . Status = ValidationStatus . Success ;
var result = ExtensibleObjectValidator . GetValidationErrors ( Entity , PropertyInfo . Name , e . Value ) ;
if ( ! result . Any ( ) )
var validationAttributes = PropertyInfo . GetValidationAttributes ( ) ;
var validationContext = new ValidationContext ( Entity )
{
return ;
}
DisplayName = PropertyInfo . Name ,
MemberName = PropertyInfo . Name
} ;
if ( LH = = null )
foreach ( var validationAttribute in validationAttributes )
{
e . MemberNames = result . First ( ) . MemberNames ;
var result = validationAttribute . GetValidationResult ( e . Value , validationContext ) ;
if ( result = = ValidationResult . Success | | result = = null )
{
continue ;
}
var errorMessage = result . ErrorMessage ;
if ( LH ! = null )
{
var formattedErrorMessage = GetDefaultErrorMessage ( validationAttribute ) ;
var errorMessageString = ValidationAttributeHelper . RevertErrorMessagePlaceholders ( formattedErrorMessage ) ;
var errorMessageArguments = ValidationMessageLocalizerAttributeFinder . FindAll ( errorMessage , errorMessageString )
? . OrderBy ( x = > x . Index )
? . Select ( x = > x . Argument ) ;
errorMessage = LH . Localize ( errorMessageString , errorMessageArguments ) ;
}
e . MemberNames = result . MemberNames ;
e . Status = ValidationStatus . Error ;
e . ErrorText = result . First ( ) . ErrorMessage ;
return ;
e . ErrorText = errorMessage ;
break ;
}
}
var formattedValidationAttributes = PropertyInfo . GetValidationAttributes ( ) ;
foreach ( var validationAttribute in formattedValidationAttributes )
private static string GetDefaultErrorMessage ( ValidationAttribute validationAttribute )
{
if ( validationAttribute is StringLengthAttribute stringLengthAttribute & & stringLengthAttribute . MinimumLength ! = 0 )
{
if ( validationAttribute . ErrorMessageResourceName = = null )
var nullable = ValidationAttributeHelper . ValidationAttributeCustomErrorMessageSetProperty . GetValue ( ( object ) validationAttribute ) as bool? ;
var flag = true ;
if ( ! ( nullable . GetValueOrDefault ( ) = = flag & nullable . HasValue ) )
{
ValidationAttributeHelper . SetDefaultErrorMessage ( validationAttribute ) ;
return ValidationAttributeHelper . SetErrorMessagePlaceholders ( "The field {0} must be a string with a minimum length of {2} and a maximum length of {1}." ) ;
}
}
var formattedResults = new List < ValidationResult > ( ) ;
var validationContext = new ValidationContext ( Entity )
{
DisplayName = PropertyInfo . Name ,
MemberName = PropertyInfo . Name
} ;
Validator . TryValidateValue ( e . Value , validationContext , formattedResults , formattedValidationAttributes ) ;
var errorMessage = result . First ( ) . ErrorMessage ;
var errorMessageString = ValidationAttributeHelper . RevertErrorMessagePlaceholders ( formattedResults . First ( ) . ErrorMessage ) ;
var errorMessageArguments = ValidationMessageLocalizerAttributeFinder . FindAll ( errorMessage , errorMessageString )
? . OrderBy ( x = > x . Index )
? . Select ( x = > x . Argument ) ;
e . MemberNames = result . First ( ) . MemberNames ;
e . Status = ValidationStatus . Error ;
e . ErrorText = LH . Localize ( errorMessageString , errorMessageArguments ) ;
return ValidationAttributeHelper . SetErrorMessagePlaceholders ( ValidationAttributeHelper . ValidationAttributeErrorMessageStringProperty . GetValue ( ( object ) validationAttribute ) as string ) ;
}
}