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


C# ValidationResult.AddErrors方法代码示例

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


在下文中一共展示了ValidationResult.AddErrors方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Evaluate

        /// <summary>
        /// Evaluates the rule for the given request.  The <b>AndRule</b> accumulates the
        /// results of all of its child rules.  It evaluates all of the child rules
        /// regardless of whether or not any particular rule passes or fails.
        /// </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();

            foreach (IValidationRule rule in children) {
                        //  evaluate the child rule
                ValidationResult childResult = rule.Evaluate(request);
                        //  if the child rule failed, set this rule to failure and add the
                        //  error(s) from the child
                if (!childResult.Passed) {
                    result.Passed = false;
                    result.AddErrors(childResult.Errors);

                    if (rule.StopOnFail || childResult.StopProcessing) {
                        result.StopProcessing = true;
                        break;
                    }
                }
            }

            return result;
        }
开发者ID:rogue-bit,项目名称:Triton-Framework,代码行数:31,代码来源:AndRule.cs

示例2: 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;
        }
开发者ID:rogue-bit,项目名称:Triton-Framework,代码行数:44,代码来源:OrRule.cs


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