public static async Task ComputeRefactoringsAsync(RefactoringContext context, LocalFunctionStatementSyntax localFunctionStatement) { if (localFunctionStatement.IsParentKind(SyntaxKind.Block)) { BlockSyntax body = localFunctionStatement.Body; if (body != null) { if (body.OpenBraceToken.Span.Contains(context.Span) || body.CloseBraceToken.Span.Contains(context.Span)) { if (context.IsRefactoringEnabled(RefactoringIdentifiers.RemoveMember)) { context.RegisterRefactoring( "Remove local function", cancellationToken => context.Document.RemoveStatementAsync(localFunctionStatement, cancellationToken)); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.DuplicateMember)) { context.RegisterRefactoring( "Duplicate local function", cancellationToken => DuplicateMemberDeclarationRefactoring.RefactorAsync(context.Document, localFunctionStatement, cancellationToken)); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.CommentOutMember)) { CommentOutRefactoring.RegisterRefactoring(context, localFunctionStatement); } } } } if (context.IsRefactoringEnabled(RefactoringIdentifiers.AddTypeParameter)) { AddTypeParameterRefactoring.ComputeRefactoring(context, localFunctionStatement); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.UseExpressionBodiedMember) && localFunctionStatement.Body?.Span.Contains(context.Span) == true && UseExpressionBodiedMemberAnalysis.IsFixable(localFunctionStatement)) { context.RegisterRefactoring( "Use expression-bodied member", cancellationToken => UseExpressionBodiedMemberRefactoring.RefactorAsync(context.Document, localFunctionStatement, cancellationToken)); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.UseListInsteadOfYield) && localFunctionStatement.Identifier.Span.Contains(context.Span)) { SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false); UseListInsteadOfYieldRefactoring.ComputeRefactoring(context, localFunctionStatement, semanticModel); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.MoveUnsafeContextToContainingDeclaration)) { MoveUnsafeContextToContainingDeclarationRefactoring.ComputeRefactoring(context, localFunctionStatement); } }
public static async Task ComputeRefactoringsAsync(RefactoringContext context, LocalFunctionStatementSyntax localFunctionStatement) { if (localFunctionStatement.IsParentKind(SyntaxKind.Block)) { BlockSyntax body = localFunctionStatement.Body; if (body != null) { if (body.OpenBraceToken.Span.Contains(context.Span) || body.CloseBraceToken.Span.Contains(context.Span)) { if (context.IsRefactoringEnabled(RefactoringIdentifiers.RemoveMember)) { context.RegisterRefactoring( "Remove local function", cancellationToken => context.Document.RemoveStatementAsync(localFunctionStatement, cancellationToken), RefactoringIdentifiers.RemoveMember); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.DuplicateMember)) { context.RegisterRefactoring( "Duplicate local function", cancellationToken => DuplicateMemberDeclarationRefactoring.RefactorAsync(context.Document, localFunctionStatement, cancellationToken), RefactoringIdentifiers.DuplicateMember); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.CommentOutMember)) { CommentOutRefactoring.RegisterRefactoring(context, localFunctionStatement); } } } } if (context.IsRefactoringEnabled(RefactoringIdentifiers.ChangeMethodReturnTypeToVoid) && context.Span.IsEmptyAndContainedInSpan(localFunctionStatement)) { await ChangeMethodReturnTypeToVoidRefactoring.ComputeRefactoringAsync(context, localFunctionStatement).ConfigureAwait(false); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.AddTypeParameter)) { AddTypeParameterRefactoring.ComputeRefactoring(context, localFunctionStatement); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.UseExpressionBodiedMember) && UseExpressionBodiedMemberRefactoring.CanRefactor(localFunctionStatement, context.Span)) { context.RegisterRefactoring( UseExpressionBodiedMemberRefactoring.Title, cancellationToken => UseExpressionBodiedMemberRefactoring.RefactorAsync(context.Document, localFunctionStatement, cancellationToken), RefactoringIdentifiers.UseExpressionBodiedMember); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.MoveUnsafeContextToContainingDeclaration)) { MoveUnsafeContextToContainingDeclarationRefactoring.ComputeRefactoring(context, localFunctionStatement); } }
public static async Task ComputeRefactoringsAsync(RefactoringContext context, LocalFunctionStatementSyntax localFunctionStatement) { if (localFunctionStatement.IsParentKind(SyntaxKind.Block)) { BlockSyntax body = localFunctionStatement.Body; if (body != null) { if (body.OpenBraceToken.Span.Contains(context.Span) || body.CloseBraceToken.Span.Contains(context.Span)) { if (context.IsRefactoringEnabled(RefactoringDescriptors.RemoveMemberDeclaration)) { context.RegisterRefactoring(CodeActionFactory.RemoveStatement(context.Document, localFunctionStatement, equivalenceKey: EquivalenceKey.Create(RefactoringDescriptors.RemoveMemberDeclaration))); } if (context.IsRefactoringEnabled(RefactoringDescriptors.CopyMemberDeclaration)) { context.RegisterRefactoring( "Copy local function", ct => CopyMemberDeclarationRefactoring.RefactorAsync( context.Document, localFunctionStatement, copyAfter: body.CloseBraceToken.Span.Contains(context.Span), ct), RefactoringDescriptors.CopyMemberDeclaration); } if (context.IsRefactoringEnabled(RefactoringDescriptors.CommentOutMemberDeclaration)) { CommentOutRefactoring.RegisterRefactoring(context, localFunctionStatement); } } } } if (context.IsRefactoringEnabled(RefactoringDescriptors.ChangeMethodReturnTypeToVoid) && context.Span.IsEmptyAndContainedInSpan(localFunctionStatement)) { await ChangeMethodReturnTypeToVoidRefactoring.ComputeRefactoringAsync(context, localFunctionStatement).ConfigureAwait(false); } if (context.IsRefactoringEnabled(RefactoringDescriptors.AddGenericParameterToDeclaration)) { AddGenericParameterToDeclarationRefactoring.ComputeRefactoring(context, localFunctionStatement); } if (context.IsRefactoringEnabled(RefactoringDescriptors.ConvertBlockBodyToExpressionBody) && ConvertBlockBodyToExpressionBodyRefactoring.CanRefactor(localFunctionStatement, context.Span)) { context.RegisterRefactoring( ConvertBlockBodyToExpressionBodyRefactoring.Title, ct => ConvertBlockBodyToExpressionBodyRefactoring.RefactorAsync(context.Document, localFunctionStatement, ct), RefactoringDescriptors.ConvertBlockBodyToExpressionBody); } if (context.IsRefactoringEnabled(RefactoringDescriptors.MoveUnsafeContextToContainingDeclaration)) { MoveUnsafeContextToContainingDeclarationRefactoring.ComputeRefactoring(context, localFunctionStatement); } }