本文整理汇总了C#中SyntaxNode.GetDiagnostics方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxNode.GetDiagnostics方法的具体用法?C# SyntaxNode.GetDiagnostics怎么用?C# SyntaxNode.GetDiagnostics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyntaxNode
的用法示例。
在下文中一共展示了SyntaxNode.GetDiagnostics方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VerifyErrorCode
private void VerifyErrorCode(SyntaxNode node, params DiagnosticId[] expected)
{
var actual = node.GetDiagnostics().Select(e => e.DiagnosticId).ToList();
// no error
if ((expected.Length == 0) && (actual.Count == 0))
{
return;
}
// Parser might give more errors than expected & that's fine
Assert.That(actual.Count, Is.GreaterThanOrEqualTo(expected.Length));
Assert.That(actual.Count, Is.LessThanOrEqualTo(int.MaxValue));
// necessary?
if (actual.Count < expected.Length)
return;
foreach (var i in expected)
Assert.Contains(i, actual); // no order
}
示例2: AddNode
private static void AddNode(ItemCollection items, SyntaxNode node, string prefix)
{
var tooltip = string.Join(Environment.NewLine, node.GetDiagnostics().Select(x => x.ToString()));
var treeViewItem = new TreeViewItem
{
Background = (node.ContainsDiagnostics) ? Brushes.Pink : Brushes.Transparent,
Foreground = (node.IsToken) ? Brushes.DarkGreen : (node.Ancestors().Any(a => a.IsToken) ? Brushes.DarkRed : Brushes.Blue),
Header = $"{prefix}{node.Kind} [{node.SourceRange.Start}..{node.SourceRange.End})",
ToolTip = string.IsNullOrEmpty(tooltip) ? null : tooltip,
Tag = node
};
foreach (var childNode in node.ChildNodes)
AddNode(treeViewItem.Items, childNode, string.Empty);
if (node.IsToken)
{
var token = (SyntaxToken) node;
foreach (var childNode in token.LeadingTrivia)
AddNode(treeViewItem.Items, childNode, "Lead: ");
foreach (var childNode in token.TrailingTrivia)
AddNode(treeViewItem.Items, childNode, "Trail: ");
}
items.Add(treeViewItem);
}