当前位置: 首页>>代码示例>>C#>>正文


C# ValidationErrorCollection.Clear方法代码示例

本文整理汇总了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>());
            }
        }
开发者ID:KCL5South,项目名称:PTPDevelopmentLibrary,代码行数:41,代码来源:DataAnnotationsValidationManager.cs


注:本文中的ValidationErrorCollection.Clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。