public static void Analyze(SyntaxNodeAnalysisContext context, StatementSyntax statement)
        {
            if (!statement.IsKind(SyntaxKind.IfStatement) ||
                ((IfStatementSyntax)statement).IsSimpleIf())
            {
                StatementSyntax embeddedStatement = GetEmbeddedStatementThatShouldBeInsideBlock(statement);

                if (embeddedStatement != null)
                {
                    context.ReportDiagnostic(
                        DiagnosticDescriptors.AddBraces,
                        embeddedStatement,
                        statement.GetTitle());
                }
            }
        }
        public static void Analyze(SyntaxNodeAnalysisContext context, StatementSyntax statement)
        {
            if (!statement.IsKind(SyntaxKind.IfStatement) ||
                ((IfStatementSyntax)statement).IsSimpleIf())
            {
                StatementSyntax embeddedStatement = EmbeddedStatementHelper.AnalyzeEmbeddedStatementToBlock(statement, ifInsideElse: false, usingInsideUsing: false);

                if (embeddedStatement != null)
                {
                    context.ReportDiagnostic(
                        DiagnosticDescriptors.AddBracesWhenExpressionSpansOverMultipleLines,
                        embeddedStatement,
                        statement.GetTitle());
                }
            }
        }
Esempio n. 3
0
        public static void RemoveStatement(
            CodeFixContext context,
            Diagnostic diagnostic,
            StatementSyntax statement,
            string title         = null,
            string additionalKey = null)
        {
            if (statement.IsEmbedded())
            {
                return;
            }

            Document document = context.Document;

            CodeAction codeAction = CodeAction.Create(
                title ?? $"Remove {statement.GetTitle()}",
                cancellationToken => document.RemoveStatementAsync(statement, cancellationToken),
                EquivalenceKeyProvider.GetEquivalenceKey(diagnostic, additionalKey));

            context.RegisterCodeFix(codeAction, diagnostic);
        }