本文整理汇总了C#中ValidationErrorCollection.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# ValidationErrorCollection.Clear方法的具体用法?C# ValidationErrorCollection.Clear怎么用?C# ValidationErrorCollection.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ValidationErrorCollection
的用法示例。
在下文中一共展示了ValidationErrorCollection.Clear方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetErrors
/// <summary>
/// Inherited from <see cref="IValidationManager"/>.
/// <para>
/// This manager assumes all objects within <paramref name="validationResult"/> are of type <see cref="ValidationResult"/>.
/// </para>
/// <para>
/// This manager assumes all <see cref="ValidationResult"/> objects within <paramref name="validationResult"/> that
/// have an empty <see cref="P:ValidationResult.MemberNames"/> collection are top level or class level issues.
/// </para>
/// </summary>
/// <param name="errorCollection">A <see cref="ValidationErrorCollection"/> that houses the validation results.</param>
/// <param name="validationResult">A <see cref="IEnumerable{T}"/> that represents the collection of validation issues that need to be applied to <paramref name="errorCollection"/>.</param>
public virtual void SetErrors(ValidationErrorCollection errorCollection, IEnumerable<object> validationResult)
{
lock (_syncObject)
{
IEnumerable<ValidationResult> vResults = validationResult.Cast<ValidationResult>();
var results =
(from g in
(from tuple in
(from r in vResults
from name in r.MemberNames
select new Tuple<string, ValidationResult>(name, r))
group tuple by tuple.Item1)
select new Tuple<string, IEnumerable<ValidationResult>>(g.Key, g.Select(a => a.Item2))).ToArray();
if (vResults.Any(a => a.MemberNames.Count() == 0))
{
Tuple<string, IEnumerable<ValidationResult>> newTuple = new Tuple<string, IEnumerable<ValidationResult>>(string.Empty, from vr in vResults
where vr.MemberNames.Count() == 0
select vr);
results = results.Concat(new Tuple<string, IEnumerable<ValidationResult>>[] { newTuple }).ToArray();
}
errorCollection.Clear();
foreach (Tuple<string, IEnumerable<ValidationResult>> item in results)
errorCollection.SetErrors(item.Item1, item.Item2.Cast<object>());
}
}