How it works...

Code refactoring providers are VS IDE extensions that can register code actions for refactoring code to a recommended pattern without introducing any functional changes. The primary API on CodeRefactoringProvider is:

  • ComputeRefactoringsAsync method (abstract): This is a method to register code actions for refactorings. This method is invoked by the code refactoring engine whenever it needs to compute the refactorings to offer on the current source line in the VS IDE. This method takes a CodeRefactoringContext argument, which contains the current span and document. CodeRefactoringProvider can map the span to syntax node in the document and analyze it to register one more code actions in the context. CodeAction contains the ...

Get Roslyn Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.