public static async Task ComputeRefactoringsAsync(RefactoringContext context, SwitchStatementSyntax switchStatement) { if (context.IsRefactoringEnabled(RefactoringIdentifiers.GenerateSwitchSections) && await GenerateSwitchSectionsRefactoring.CanRefactorAsync(context, switchStatement).ConfigureAwait(false)) { context.RegisterRefactoring( "Generate sections", cancellationToken => { return(GenerateSwitchSectionsRefactoring.RefactorAsync( context.Document, switchStatement, cancellationToken)); }); } SelectedSwitchSectionsRefactoring.ComputeRefactorings(context, switchStatement); if (context.IsRefactoringEnabled(RefactoringIdentifiers.ReplaceSwitchWithIfElse) && (switchStatement.SwitchKeyword.Span.Contains(context.Span) || context.Span.IsBetweenSpans(switchStatement)) && switchStatement .Sections .Any(section => !section.Labels.Contains(SyntaxKind.DefaultSwitchLabel))) { context.RegisterRefactoring( "Replace switch with if-else", cancellationToken => ReplaceSwitchWithIfElseRefactoring.RefactorAsync(context.Document, switchStatement, cancellationToken)); } }
public static async Task ComputeRefactoringsAsync(RefactoringContext context, SwitchStatementSyntax switchStatement) { if (context.IsRefactoringEnabled(RefactoringIdentifiers.GenerateSwitchSections) && await GenerateSwitchSectionsRefactoring.CanRefactorAsync(context, switchStatement).ConfigureAwait(false)) { context.RegisterRefactoring( "Generate sections", cancellationToken => GenerateSwitchSectionsRefactoring.RefactorAsync(context.Document, switchStatement, cancellationToken)); } SelectedSwitchSectionsRefactoring.ComputeRefactorings(context, switchStatement); if (context.IsRefactoringEnabled(RefactoringIdentifiers.ReplaceSwitchWithIfElse) && context.Span.IsBetweenSpans(switchStatement)) { ReplaceSwitchWithIfElseRefactoring.ComputeRefactoring(context, switchStatement); } }