Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between a Roslyn CodeFix and Refactoring?

Tags:

c#

roslyn

I have been scouring all possible documentation I could find about the Roslyn APIs but I could not find an answer to this simple question.

I know a CodeFix inherits from CodeFixProvider and provides a Code Fix. I also know that a Refactoring inherits from CodeRefactoringProvider and provides a Refactoring. One difference I found is that for some reason you cannot redistribute Refactorings using Nuget, only through a VSIX, while you can redistribute a CodeFix using both.

But what exactly is a Code Fix and what is a Refactoring? What can one do that the other cannot?

like image 301
Phoenix Avatar asked Jul 03 '18 10:07

Phoenix


People also ask

What is refactoring IDE?

Go Up to The Code Editor Index (IDE Tutorial) Refactoring is the process of improving your code without changing its external functionality. For example, you can turn a selected code fragment into a method by using the extract refactoring method.

How to Refactor code in Visual Studio code on a Mac?

Press Option (⌥)+Enter anywhere on a line to see a list of available Quick Actions and refactorings.


1 Answers

A Code Fix is for where you've identified an error or mistake in the code and can deduce how to correct the code.

A Refactoring is a change to the code that usually will make it neither more nor less correct. It's not unusual to offer multiple refactorings that will transform the code between various forms, including, often, back to the form it was in before someone accepted any refactoring. In contrast, it would be rare in the extreme to find another Code Fix (in the same package) that transformed code into a form that another Code Fix could apply to.

like image 151
Damien_The_Unbeliever Avatar answered Oct 26 '22 15:10

Damien_The_Unbeliever