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


C# Result.FailBecause方法代码示例

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


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

示例1: WalkObjectTree

        static object WalkObjectTree(List<ChainStep> chain, ref string path, Result result, IList<INamedPredicate> predicates)
        {
            var remainingChain = chain;
            while (remainingChain.Count > 1)
            {
                var step = remainingChain.First();
                remainingChain = remainingChain.Skip(1).ToList();

                var pathHere = path + "." + step.Name;
                object next;
                try {
                    next = result.Target.Get(step.Name);
                } catch (FastFailureException) {
                    result.FailBecause(pathHere + " is not a valid path");
                    return null;
                }

                if (next == null) {
                    result.FailBecause(pathHere + " is null or not accessible");
                    return null;
                }

                if (next is IEnumerable)
                {
                    string stepMsg;
                    var container = FilterWithNamedPredicate((IEnumerable)next, step, out stepMsg);
                    pathHere += stepMsg;
                    switch (step.ListAssertionType)
                    {
                        case ListAssertion.Single:
                        case ListAssertion.Simple:
                            if ( ! StepSingle(result, pathHere, container, out next)) return null;
                            break;

                        case ListAssertion.Index:
                            if ( ! StepIndex(result, step, container, out next, ref pathHere)) return null;
                            break;

                        case ListAssertion.All:
                            CheckAllSubpaths(result, predicates, pathHere, remainingChain, container);
                            return null;

                        case ListAssertion.Any:
                            CheckAnySubpaths(result, predicates, remainingChain, pathHere, container);
                            return null;

                        default: throw new Exception("Unexpected list assertion type");
                    }
                }

                result.Target = next;
                path = pathHere;
            }

            return ApplyPredicatesToEndOfChain(ref path, result, predicates, remainingChain);
        }
开发者ID:i-e-b,项目名称:DynamicValidation,代码行数:56,代码来源:Check.cs

示例2: StepSingle

 static bool StepSingle(Result result, string pathHere, object[] container, out object resultTarget)
 {
     resultTarget = null;
     if (container.Length > 1)
     {
         result.FailBecause(pathHere + " has length of " + container.Length + ", expected 1");
         return false;
     }
     if (container.Length < 1)
     {
         result.FailBecause(pathHere + " has no items");
         return false;
     }
     resultTarget = container[0];
     return true;
 }
开发者ID:i-e-b,项目名称:DynamicValidation,代码行数:16,代码来源:Check.cs

示例3: ApplyPredicatesToSimpleTerminal

 static void ApplyPredicatesToSimpleTerminal(string path, Result result, IEnumerable<INamedPredicate> predicates)
 {
     foreach (var predicate in predicates)
     {
         string message;
         if (!predicate.Matches(result.Target, out message)) result.FailBecause(path + " " + message);
     }
 }
开发者ID:i-e-b,项目名称:DynamicValidation,代码行数:8,代码来源:Check.cs

示例4: StepIndex

 static bool StepIndex(Result result, ChainStep step, object[] container, out object next, ref string pathHere)
 {
     next = null;
     if (step.SingleIndex < 0 || step.SingleIndex >= container.Length)
     {
         result.FailBecause(pathHere + " has length of " + container.Length + ", tried to access index " + step.SingleIndex);
         return false;
     }
     pathHere += "[" + step.SingleIndex + "]";
     next = container[step.SingleIndex];
     return true;
 }
开发者ID:i-e-b,项目名称:DynamicValidation,代码行数:12,代码来源:Check.cs

示例5: ApplyPredicatesToEndOfChain

        static object ApplyPredicatesToEndOfChain(ref string path, Result result, IList<INamedPredicate> predicates, List<ChainStep> remainingChain)
        {
            ChainStep step;
            if (remainingChain.Count == 1)
            {
                step = remainingChain[0];
                try
                {
                    result.Target = result.Target.Get(step.Name);
                    path += "." + step.Name;
                }
                catch (FastFailureException)
                {
                    result.FailBecause(path + "." + step.Name + " is not a valid path");
                    return null;
                }
            } else
            {
                step = ChainStep.SimpleStep("?");
            }

            if (result.Target is IEnumerable)
            {
                ApplyPredicatesToTerminalEnumerable(path, result, predicates, step);
            }
            else
            {
                ApplyPredicatesToSimpleTerminal(path, result, predicates);
            }
            return result.Target;
        }
开发者ID:i-e-b,项目名称:DynamicValidation,代码行数:31,代码来源:Check.cs


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