本文整理汇总了C#中ValidationErrorCollection.ContainsKey方法的典型用法代码示例。如果您正苦于以下问题:C# ValidationErrorCollection.ContainsKey方法的具体用法?C# ValidationErrorCollection.ContainsKey怎么用?C# ValidationErrorCollection.ContainsKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ValidationErrorCollection
的用法示例。
在下文中一共展示了ValidationErrorCollection.ContainsKey方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetMemberErrors
/// <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 removes all <see cref="ValidationResult"/> objects from the property represented by <paramref name="member"/>.
/// If any of the removed <see cref="ValidationResult"/> objects are present for any other properties on the object, those are removed as well.
/// </para>
/// <remarks>This effectively means that if a single ValidationResult spans multiple properties, and one of those properties changes (i.e. is revalidated)
/// then the ValdiationResult will be removed from all of the spaned properties.</remarks>
/// </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>
/// <param name="member">A string representing the name of the property that is being validated.</param>
public virtual void SetMemberErrors(ValidationErrorCollection errorCollection, IEnumerable<object> validationResult, string member)
{
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();
}
if (errorCollection.ContainsKey(member))
{
var itemsToRemove =
(from g in
(from tuple in
(from r in errorCollection[member].Cast<ValidationResult>()
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();
foreach (Tuple<string, IEnumerable<ValidationResult>> item in itemsToRemove)
errorCollection.RemoveErrors(item.Item1, item.Item2.Cast<object>());
}
foreach (Tuple<string, IEnumerable<ValidationResult>> item in results)
errorCollection.SetErrors(item.Item1, item.Item2.Cast<object>());
}
}