Skip to content
| Marketplace
Sign in
Visual Studio>Tools>Tidy C#

Tidy C#

Geeks Ltd

|
5,715 installs
| (5) | Free
Clean up your C# code.

A Visual Studio extension that adds a few enhancements to improve C# code development. It provides a list of automatic refactorig tools for cleaner C# code.

  1. Close all open windows
  2. Right click on a C# file, folder, project or even the whole solution.
  3. Select "Clean up C#..."
  4. In the pop-up select the clean up actions you are interested in.
  5. Click Run

Supported auto-change rules

You can select any of the following supported rules to apply to all of your code in one go.

The ones highlighted as red below are controversal and subjective. Feel free to exclude them if you don't like them. They are included in this tool because they reduce the code size, making it quicker to see the main elements of the code, which is why we like them.

  • Remove and sort Usings 
  • Normalize white spaces 
    • No { and } for short blocks (single statement and < 70 chars)
    • Blank line between } and the next statement. 
    • Blank line between methods. 
    • Trim the file Space before comment text: //TODO: => // TODO: 
    • No blank lines immediately after { and immediately before } 
    • No duplicate blank lines between "Usings .." 
    • No duplicate blank lines between comments 
    • No duplicate blank lines between namespace members 
    • No duplicate blank lines between class members 
    • No duplicate blank lines between method statement 
  • Remove unnecessary explicit 'private' where its the default 
    • Remove 'private' from properties 
    • Remove 'private' from methods 
    • Remove 'private' from fields 
    • Remove 'private' from nested classes 
  • Small methods properties -> Expression bodied 
    • Convert ReadOnly Property => ReadOnly Property with only a single return statement and lenth less than 100 chars
    • Convert Methods => Method with only a single return statement and lenth less than 100 chars
  • Simplify async calls
    • Remove unnecessary async / await pair (simply return the task). 
  • Convert traditional properties to auto-properties 
  • Use 'var' for variable declarations
  • Compact multiple class field declarations into one line 
    • Declare multiple class fields [with the same type] on the same line (if total size < 80 chars) 
    • Remove unnecessary explicit "=null" from class fields. 
    • Remove unnecessary explicit "=0" or "=false" from class fields.
  • Remove unnecessary "this." 
    • Remove from property calls 
    • Remove from field calls 
    • Remove from method calls 
  • Use camelCase for... 
    • Local variable declarations 
    • Method parameters 
  • Class field and const casing... 
    • Const fields: USE_THIS_FORMAT 
    • Class fields: Change _something -> Something or something 
  • Move constructors before methods 
  • Remove unnecessary 'Attribute (e.g. [SomethingAttribute] -> [Something]) 
  • Compact small if/else blocks 
  • Use C# alias type names (e.g. System.Int32 -> int) 

 

It will then open each file, apply the clean up actions, save and close. It can take a few minutes for a large codebase.

Recommendation

- Check out all of its changes in your source control tool diff tool.

- This project is open source and available on GitHub. All contributions are welcome.

  • Contact us
  • Jobs
  • Privacy
  • Terms of use
  • Trademarks
© 2021 Microsoft