本文整理汇总了C#中IValidationErrors.AddError方法的典型用法代码示例。如果您正苦于以下问题:C# IValidationErrors.AddError方法的具体用法?C# IValidationErrors.AddError怎么用?C# IValidationErrors.AddError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IValidationErrors
的用法示例。
在下文中一共展示了IValidationErrors.AddError方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnInvalid
/// <summary>
/// Called when associated validator is invalid.
/// </summary>
/// <param name="validationContext">Validation context.</param>
/// <param name="contextParams">Additional context parameters.</param>
/// <param name="errors">Validation errors container.</param>
protected override void OnInvalid(object validationContext, IDictionary<string, object> contextParams, IValidationErrors errors)
{
ErrorMessage error = CreateErrorMessage(validationContext, contextParams);
foreach (string provider in this.providers)
{
errors.AddError(provider.Trim(), error);
}
}
示例2: SetInvalid
/// <summary>
/// Marks this binding's state as invalid for this validationErrors collection.
/// Returns false if <paramref name="validationErrors"/> is null.
/// </summary>
/// <param name="validationErrors"></param>
/// <returns>false, if validationErrors is null</returns>
protected bool SetInvalid(IValidationErrors validationErrors)
{
if (validationErrors != null)
{
foreach (string provider in this.ErrorProviders)
{
validationErrors.AddError(provider, this.ErrorMessage);
}
return true;
}
return false;
}
示例3: WhenMultipleValidatorsReturnTrue
private void WhenMultipleValidatorsReturnTrue(ExclusiveValidatorGroup vg, IValidationErrors errors)
{
vg.Actions.Add(new ErrorMessageAction("exclusiveError", "exclusiveErrors"));
vg.Validators.Add(new FalseValidator());
vg.Validators.Add(new TrueValidator());
vg.Validators.Add(new TrueValidator());
vg.Validators.Add(new FalseValidator());
errors.AddError("existingErrors", new ErrorMessage("error", null));
bool valid = vg.Validate(new object(), errors);
Assert.IsFalse(valid, "Validation should not succeed when multiple inner validators return true.");
Assert.AreEqual(1, errors.GetErrors("exclusiveErrors").Count);
Assert.AreEqual(1, errors.GetErrors("existingErrors").Count);
}