コード例 #1
0
        private static IEnumerable <SolutionStyleError> CheckNonBracesStatements(SyntaxNodeOrToken rootStatementSyntax)
        {
            var rootLine    = rootStatementSyntax.GetStartLine();
            var rootEndLine = rootStatementSyntax.GetConditionEndLine();
            var parent      = rootStatementSyntax.GetParent();
            var rootStart   = rootStatementSyntax.GetValidationStartIndexInSpaces();

            if (parent != null && parent.Kind == SyntaxKind.Block)
            {
                var parentLine = parent.GetStartLine();
                if (parentLine == rootLine)
                {
                    yield break;
                }
                var parentStart = parent.GetValidationStartIndexInSpaces();
                if (rootStart == 0)
                {
                    yield break;
                }
                var errorType = GetIndentErrorType(rootStart, parentStart, rootLine, parentLine);
                if (errorType.HasValue)
                {
                    yield return(new SolutionStyleError(errorType.Value, rootStatementSyntax));

                    yield break;
                }
            }

            var statementClauses = rootStatementSyntax.SyntaxNode.CreateStatements().ToArray();
            var reports          = ValidateStatementClauses(statementClauses, rootStatementSyntax, rootStart, rootLine, rootEndLine);

            foreach (var report in reports)
            {
                yield return(report);
            }
        }