Beispiel #1
0
        public sealed override async Task ComputeRefactoringsAsync(CodeRefactoringContext context)
        {
            var isCallPoint = await LocalVariableCodeRefactoring.IsCallPoint(context);

            if (isCallPoint)
            {
                var action = CodeAction.Create(refactoringName, c => LocalVariableCodeRefactoring.DeclareLocalVariable(context, "var"));
                context.RegisterRefactoring(action);
            }
        }
Beispiel #2
0
        protected async Task <String> GetTypeName(CodeRefactoringContext context)
        {
            var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);

            var currentNode   = root.FindNode(context.Span);
            var semanticModel = await context.Document.GetSemanticModelAsync(context.CancellationToken);

            var statement = currentNode.AncestorsAndSelf().OfType <ExpressionStatementSyntax>().FirstOrDefault();

            return(LocalVariableCodeRefactoring.GetNamedType(semanticModel, statement).MetadataName);
        }