本文整理汇总了C#中ValidationContext.GetFragment方法的典型用法代码示例。如果您正苦于以下问题:C# ValidationContext.GetFragment方法的具体用法?C# ValidationContext.GetFragment怎么用?C# ValidationContext.GetFragment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ValidationContext
的用法示例。
在下文中一共展示了ValidationContext.GetFragment方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: detectCycleRecursive
private void detectCycleRecursive(
FragmentDefinition fragment,
Stack<FragmentSpread> spreadPath,
LightweightCache<string, bool> visitedFrags,
LightweightCache<string, int> spreadPathIndexByName,
ValidationContext context)
{
var fragmentName = fragment.Name;
visitedFrags[fragmentName] = true;
var spreadNodes = context.GetFragmentSpreads(fragment.SelectionSet).ToArray();
if (!spreadNodes.Any())
{
return;
}
spreadPathIndexByName[fragmentName] = spreadPath.Count;
foreach (var spreadNode in spreadNodes)
{
var spreadName = spreadNode.Name;
var cycleIndex = spreadPathIndexByName[spreadName];
if (cycleIndex == -1)
{
spreadPath.Push(spreadNode);
if (!visitedFrags[spreadName])
{
var spreadFragment = context.GetFragment(spreadName);
if (spreadFragment != null)
{
detectCycleRecursive(
spreadFragment,
spreadPath,
visitedFrags,
spreadPathIndexByName,
context);
}
}
spreadPath.Pop();
}
else
{
var cyclePath = spreadPath.Reverse().Skip(cycleIndex).ToArray();
var nodes = cyclePath.OfType<INode>().Concat(new[] {spreadNode}).ToArray();
context.ReportError(new ValidationError(
context.OriginalQuery,
"5.4",
CycleErrorMessage(spreadName, cyclePath.Select(x => x.Name).ToArray()),
nodes));
}
}
spreadPathIndexByName[fragmentName] = -1;
}
示例2: Validate
public INodeVisitor Validate(ValidationContext context)
{
return new EnterLeaveListener(_ =>
{
_.Match<FragmentSpread>(node =>
{
var fragmentName = node.Name;
var fragment = context.GetFragment(fragmentName);
if (fragment == null)
{
var error = new ValidationError(context.OriginalQuery, "5.4.2.1", UnknownFragmentMessage(fragmentName), node);
context.ReportError(error);
}
});
});
}
示例3: getFragmentType
private GraphType getFragmentType(ValidationContext context, string name)
{
var frag = context.GetFragment(name);
return frag.Type.GraphTypeFromType(context.Schema);
}