コード例 #1
0
        public static async Task ComputeRefactoringsAsync(RefactoringContext context, LiteralExpressionSyntax literalExpression)
        {
            switch (literalExpression.Kind())
            {
            case SyntaxKind.TrueLiteralExpression:
            case SyntaxKind.FalseLiteralExpression:
            {
                if (context.IsRefactoringEnabled(RefactoringIdentifiers.NegateBooleanLiteral) &&
                    literalExpression.Span.Contains(context.Span))
                {
                    context.RegisterRefactoring(
                        "Negate boolean literal",
                        cancellationToken => NegateBooleanLiteralRefactoring.RefactorAsync(context.Document, literalExpression, cancellationToken));
                }

                break;
            }

            case SyntaxKind.StringLiteralExpression:
            {
                if (context.Span.IsContainedInSpanOrBetweenSpans(literalExpression))
                {
                    await StringLiteralExpressionRefactoring.ComputeRefactoringsAsync(context, literalExpression).ConfigureAwait(false);
                }

                break;
            }
            }
        }
コード例 #2
0
        public static void ComputeRefactorings(RefactoringContext context, LiteralExpressionSyntax literalExpression)
        {
            switch (literalExpression.Kind())
            {
            case SyntaxKind.TrueLiteralExpression:
            case SyntaxKind.FalseLiteralExpression:
            {
                if (context.IsRefactoringEnabled(RefactoringIdentifiers.NegateBooleanLiteral) &&
                    literalExpression.Span.Contains(context.Span))
                {
                    context.RegisterRefactoring(
                        "Negate boolean literal",
                        cancellationToken => NegateBooleanLiteralRefactoring.RefactorAsync(context.Document, literalExpression, cancellationToken));
                }

                break;
            }

            case SyntaxKind.StringLiteralExpression:
            {
                StringLiteralExpressionRefactoring.ComputeRefactorings(context, literalExpression);
                break;
            }
            }
        }
コード例 #3
0
        public static async Task ComputeRefactoringsAsync(RefactoringContext context, LiteralExpressionSyntax literalExpression)
        {
            switch (literalExpression.Kind())
            {
            case SyntaxKind.TrueLiteralExpression:
            case SyntaxKind.FalseLiteralExpression:
            {
                if (context.IsRefactoringEnabled(RefactoringDescriptors.InvertBooleanLiteral) &&
                    literalExpression.Span.Contains(context.Span))
                {
                    context.RegisterRefactoring(
                        "Invert boolean literal",
                        ct => InvertBooleanLiteralRefactoring.RefactorAsync(context.Document, literalExpression, ct),
                        RefactoringDescriptors.InvertBooleanLiteral);
                }

                break;
            }

            case SyntaxKind.StringLiteralExpression:
            {
                if (context.Span.IsContainedInSpanOrBetweenSpans(literalExpression))
                {
                    await StringLiteralExpressionRefactoring.ComputeRefactoringsAsync(context, literalExpression).ConfigureAwait(false);
                }

                break;
            }

            case SyntaxKind.NumericLiteralExpression:
            {
                if (context.IsRefactoringEnabled(RefactoringDescriptors.ConvertHexadecimalLiteralToDecimalLiteral) &&
                    context.Span.IsBetweenSpans(literalExpression))
                {
                    ConvertHexadecimalLiteralToDecimalLiteralRefactoring.ComputeRefactoring(context, literalExpression);
                }

                break;
            }
            }
        }