public static async Task ComputeRefactoringAsync(RefactoringContext context, UsingStatementSyntax usingStatement)
        {
            VariableDeclarationSyntax declaration = usingStatement.Declaration;

            if (declaration != null &&
                usingStatement.IsParentKind(SyntaxKind.Block))
            {
                SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                if (semanticModel.ContainsDiagnostic(
                        CSharpErrorCodes.TypeUsedInUsingStatementMustBeImplicitlyConvertibleToIDisposable,
                        declaration.Span,
                        context.CancellationToken))
                {
                    if (context.Span.IsContainedInSpanOrBetweenSpans(declaration))
                    {
                        RegisterRefactoring(context, usingStatement);
                    }
                }
                else if (context.Span.IsBetweenSpans(declaration))
                {
                    RegisterRefactoring(context, usingStatement);
                }
            }
        }
예제 #2
0
        public static async Task ComputeRefactoringAsync(RefactoringContext context, LiteralExpressionSyntax literalExpression)
        {
            if (literalExpression.IsKind(SyntaxKind.StringLiteralExpression) &&
                literalExpression.Token.ValueText.Length == 1)
            {
                SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                if (semanticModel.ContainsDiagnostic(CSharpErrorCodes.CannotImplicitlyConvertType, literalExpression.Span, context.CancellationToken))
                {
                    context.RegisterRefactoring(
                        "Replace string literal with character literal",
                        cancellationToken => RefactorAsync(context.Document, literalExpression, cancellationToken));
                }
            }
        }