我如何能识别和分析局部变量和参数与罗斯林代码诊断? [英] How can I identify and analyze local variables and parameters with Roslyn code diagnostics?

查看:368
本文介绍了我如何能识别和分析局部变量和参数与罗斯林代码诊断?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很困惑使用哪种方法 AnalysisContext背景对象上有每个函数/方法的局部变量anazlyed:要么 RegisterSymbolAction() RegisterSyntaxNodeAction()

I'm confused which method to use on the AnalysisContext context object to have every function/method's local variables anazlyed: either RegisterSymbolAction() or RegisterSyntaxNodeAction().

很可能 RegisterSymbolAction()按样品诊断与代码修复(的NuGet + VSIX)在<一个HREF =https://visualstudiogallery.msdn.microsoft.com/849f3ab1-05cf-4682-b4af-ef995e2aa1a5相对=nofollow>罗斯林SDK项目Templates.vsix 。

It's likely RegisterSymbolAction() as per the sample Diagnostic with Code Fix (NuGet + VSIX) in the Roslyn SDK Project Templates.vsix.

我用一个简单的控制台应用程序的调试的Main()有一个类型的局部变量屈指可数字符串 INT

I'm debugging using a simple console app whose Main() has a handful of local variables of type string and int.

我已经试过这两个,但也不会引发在各自的 AnalyzeSymbol()回调方法进行分析的变量。在每个这些回调方法断点没有被击中的局部变量。

I've tried these two, but neither will trigger any variable to be analyzed in their respective AnalyzeSymbol() callback methods. Breakpoint within each of those callback methods don't get hit for the local variables.

我怎样才能得到局部变量的回调方法来分析 AnalyzeSymbol()和/或我在做什么错了?

How can I get local variables to be analyzed in the callback method AnalyzeSymbol() and/or what am I doing wrong?

var symbolsToActOn = new[] { SymbolKind.Local, SymbolKind.Parameter, SymbolKind.Field }; 
context.RegisterSymbolAction(AnalyzeSymbol, symbolsToActOn);

var syntaxTypes = new[] { SyntaxKind.IdentifierName, SyntaxKind.IdentifierToken, SyntaxKind.Parameter };
context.RegisterSyntaxNodeAction(AnalyzeSyntaxNode, syntaxTypes);



我的示范项目是在GitHub上仔细看看,具体件作品是在的 DiagnosticAnalyzer.cs

My demo project is on GitHub for a closer look, and the specific piece is in DiagnosticAnalyzer.cs.

推荐答案

不幸的是 RegisterSymbolAction 目前只工作方法及以上。当地人和参数,你需要使用 RegisterSyntaxNodeAction 。我们希望在以后的版本来解决这个问题。

Unfortunately RegisterSymbolAction currently only work methods and above. For locals, and parameters you need to use RegisterSyntaxNodeAction. We hope to address this in a later build.

这篇关于我如何能识别和分析局部变量和参数与罗斯林代码诊断?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆