本文整理汇总了C#中SyntaxNode.GetAnnotatedNodesAndTokens方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxNode.GetAnnotatedNodesAndTokens方法的具体用法?C# SyntaxNode.GetAnnotatedNodesAndTokens怎么用?C# SyntaxNode.GetAnnotatedNodesAndTokens使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyntaxNode
的用法示例。
在下文中一共展示了SyntaxNode.GetAnnotatedNodesAndTokens方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTextSpansFromAnnotation
private IEnumerable<TextSpan> GetTextSpansFromAnnotation(SyntaxNode node, List<ValueTuple<SyntaxAnnotation, SyntaxAnnotation>> annotations, CancellationToken cancellationToken)
{
// now try to retrieve text span from annotations injected to the node
foreach (var annotationPair in annotations)
{
cancellationToken.ThrowIfCancellationRequested();
var previousMarkerAnnotation = annotationPair.Item1;
var nextMarkerAnnotation = annotationPair.Item2;
var previousTokenMarker = SpanMarker.FromAnnotation(previousMarkerAnnotation);
var nextTokenMarker = SpanMarker.FromAnnotation(nextMarkerAnnotation);
var previousTokens = node.GetAnnotatedNodesAndTokens(previousMarkerAnnotation).Where(n => n.IsToken).Select(n => n.AsToken());
var nextTokens = node.GetAnnotatedNodesAndTokens(nextMarkerAnnotation).Where(n => n.IsToken).Select(n => n.AsToken());
// check whether we can use tokens we got back from the node
TextSpan span;
if (TryGetTextSpanFromAnnotation(previousTokenMarker, nextTokenMarker, node, previousTokens, nextTokens, out span))
{
yield return span;
}
}
}
示例2: TestAnnotations
private void TestAnnotations(
string expectedText,
IList<TextSpan> expectedSpans,
SyntaxNode fixedRoot,
string annotationKind,
bool compareTokens)
{
expectedSpans = expectedSpans ?? new List<TextSpan>();
var annotatedTokens = fixedRoot.GetAnnotatedNodesAndTokens(annotationKind).Select(n => (SyntaxToken)n).ToList();
Assert.Equal(expectedSpans.Count, annotatedTokens.Count);
if (expectedSpans.Count > 0)
{
var expectedTokens = TokenUtilities.GetTokens(TokenUtilities.GetSyntaxRoot(expectedText, GetLanguage()));
var actualTokens = TokenUtilities.GetTokens(fixedRoot);
for (var i = 0; i < Math.Min(expectedTokens.Count, actualTokens.Count); i++)
{
var expectedToken = expectedTokens[i];
var actualToken = actualTokens[i];
var actualIsConflict = annotatedTokens.Contains(actualToken);
var expectedIsConflict = expectedSpans.Contains(expectedToken.Span);
Assert.Equal(expectedIsConflict, actualIsConflict);
}
}
}