/// <summary>
/// Sets the field validation result.
/// </summary>
/// <param name="validationResult">The field validation result.</param>
/// <exception cref="ArgumentNullException">The <paramref name="validationResult"/> is <c>null</c>.</exception>
protected void SetFieldValidationResult(IFieldValidationResult validationResult)
{
Argument.IsNotNull("validationResult", validationResult);
if (string.IsNullOrEmpty(validationResult.Message))
{
return;
}
var previousValidations = _internalValidationContext.GetFieldValidations(validationResult.PropertyName);
// First, check if the same error already exists
bool alreadyExists = (from previousValidation in previousValidations
where string.Compare(previousValidation.Message, validationResult.Message, StringComparison.Ordinal) == 0
select previousValidation).Any();
if (alreadyExists)
{
return;
}
_internalValidationContext.AddFieldValidationResult(validationResult);
if (!IsValidating)
{
switch (validationResult.ValidationResultType)
{
case ValidationResultType.Warning:
NotifyWarningsChanged(validationResult.PropertyName, true);
break;
case ValidationResultType.Error:
NotifyErrorsChanged(validationResult.PropertyName, true);
break;
}
}
}