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


C# ValidationErrorCollection.RemoveErrors方法代码示例

本文整理汇总了C#中ValidationErrorCollection.RemoveErrors方法的典型用法代码示例。如果您正苦于以下问题:C# ValidationErrorCollection.RemoveErrors方法的具体用法?C# ValidationErrorCollection.RemoveErrors怎么用?C# ValidationErrorCollection.RemoveErrors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ValidationErrorCollection的用法示例。


在下文中一共展示了ValidationErrorCollection.RemoveErrors方法的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>());
            }
        }
开发者ID:KCL5South,项目名称:PTPDevelopmentLibrary,代码行数:57,代码来源:DataAnnotationsValidationManager.cs


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