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

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.
主站蜘蛛池模板: 桑植县| 乌兰察布市| 剑阁县| 二手房| 天全县| 莎车县| 长寿区| 绥滨县| 和平区| 西藏| 昭觉县| 彭山县| 丰原市| 沙湾县| 宁武县| 新河县| 独山县| 岱山县| 灵台县| 衡阳县| 毕节市| 天等县| 余干县| 黎川县| 栾川县| 资中县| 浦城县| 张北县| 伊吾县| 民乐县| 托克逊县| 乌兰察布市| 安岳县| 夏邑县| 海伦市| 安徽省| 峡江县| 鹰潭市| 江阴市| 视频| 文登市|