本文整理汇总了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);
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}