本文整理汇总了C#中SyntaxNode.ChildThatContainsPosition方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxNode.ChildThatContainsPosition方法的具体用法?C# SyntaxNode.ChildThatContainsPosition怎么用?C# SyntaxNode.ChildThatContainsPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyntaxNode
的用法示例。
在下文中一共展示了SyntaxNode.ChildThatContainsPosition方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindLeafNodeAndPartner
public static void FindLeafNodeAndPartner(SyntaxNode leftRoot, int leftPosition, SyntaxNode rightRoot, out SyntaxNode leftNode, out SyntaxNode rightNode)
{
leftNode = leftRoot;
rightNode = rightRoot;
while (true)
{
Debug.Assert(leftNode.RawKind == rightNode.RawKind);
var leftChild = leftNode.ChildThatContainsPosition(leftPosition, out var childIndex);
if (leftChild.IsToken)
{
return;
}
rightNode = rightNode.ChildNodesAndTokens()[childIndex].AsNode();
leftNode = leftChild.AsNode();
}
}
示例2: FindPartner
public static SyntaxNode FindPartner(SyntaxNode leftRoot, SyntaxNode rightRoot, SyntaxNode leftNode)
{
// Finding a partner of a zero-width node is complicated and not supported atm:
Debug.Assert(leftNode.FullSpan.Length > 0);
Debug.Assert(leftNode.SyntaxTree == leftRoot.SyntaxTree);
SyntaxNode originalLeftNode = leftNode;
int leftPosition = leftNode.SpanStart;
leftNode = leftRoot;
SyntaxNode rightNode = rightRoot;
while (leftNode != originalLeftNode)
{
Debug.Assert(leftNode.RawKind == rightNode.RawKind);
var leftChild = leftNode.ChildThatContainsPosition(leftPosition, out var childIndex);
// Can only happen when searching for zero-width node.
Debug.Assert(!leftChild.IsToken);
rightNode = rightNode.ChildNodesAndTokens()[childIndex].AsNode();
leftNode = leftChild.AsNode();
}
return rightNode;
}