本文整理汇总了C#中ValidationResult.ClearErrors方法的典型用法代码示例。如果您正苦于以下问题:C# ValidationResult.ClearErrors方法的具体用法?C# ValidationResult.ClearErrors怎么用?C# ValidationResult.ClearErrors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ValidationResult
的用法示例。
在下文中一共展示了ValidationResult.ClearErrors方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Evaluate
/// <summary>
/// Evaluates the rule for the given request. The <b>OrRule</b> short circuits
/// on the first successful child rule, with a passed status.
/// </summary>
/// <param name="request">The <b>MvcRequest</b> to evaluate the rule for.</param>
/// <returns>A <b>ValidationResult</b> indicating the result of evaluating the
/// rule and any validation errors that occurred.</returns>
public override ValidationResult Evaluate(
MvcRequest request)
{
ValidationResult result = new ValidationResult { Passed = false };
// TODO: if cnt is 0 should we return true or false??
int cnt = children.Count;
for (int k = 0; k < cnt && !result.Passed; k++) {
IValidationRule rule = children[k];
// evaluate the child rule
ValidationResult childResult = rule.Evaluate(request);
// clear out any previous validation errors
result.ClearErrors();
// if the child rule passed, set this rule to passed,
// if not, add the errors from the child to the OrRule's result
if (childResult.Passed) {
result.Passed = true;
} else {
result.AddErrors(childResult.Errors);
if (rule.StopOnFail || childResult.StopProcessing) {
result.StopProcessing = true;
break;
}
}
}
// if the OrRule did not pass and the is a specific error identified
// for the OrRule, replace any errors from the children with the one
// for the OrRule
if (!result.Passed && (ErrorId != 0)) {
result.ClearErrors();
result.AddError(Field, ErrorId);
}
return result;
}