官术网_书友最值得收藏!

How it works...

Syntax tree analyzers register callbacks to analyze syntax of all source files in the compilation. Our analysis works by getting the roots of the syntax tree and then operating on all the descendant syntax nodes of the roots which are of type StatementSyntax. First, we note that a block statement is itself an aggregate statement, and by definition has curly braces, so we skip past these.

// Skip analyzing block statements.
if (statement is BlockSyntax)
{
continue;
}

We then perform syntactic checks for the parent of statement syntax. If the parent of the statement is also a statement, but not a block with curly braces, then we report a diagnostic on the first syntax token of the statement recommending usage of curly braces.

// Report issue for all statements that are nested within a statement,
// but not a block statement.
if (statement.Parent is StatementSyntax && !(statement.Parent is BlockSyntax))
{
var diagnostic = Diagnostic.Create(Rule, statement.GetFirstToken().GetLocation());
syntaxTreeContext.ReportDiagnostic(diagnostic);
}
SyntaxTreeAnalysisContext provided to syntax tree actions does not expose the semantic model for the source file, hence no semantic analysis can be performed within a syntax tree action.
主站蜘蛛池模板: 武定县| 游戏| 永靖县| 怀集县| 兴业县| 天全县| 都江堰市| 梁河县| 玛纳斯县| 江阴市| 颍上县| 衢州市| 四子王旗| 合山市| 密山市| 扶风县| 吴川市| 于都县| 东宁县| 祥云县| 太仆寺旗| 石阡县| 乌拉特中旗| 东至县| 射洪县| 砀山县| 都江堰市| 专栏| 太湖县| 石河子市| 乌审旗| 安化县| 甘谷县| 佛教| 淮北市| 固原市| 葵青区| 崇明县| 马龙县| 三江| 社会|