Search code examples
c#visual-studiocurly-bracescode-cleanupcodemaid

How to Remove Braces on Single-Line Statement?


Could anyone advise how to remove braces from any single-line statements? (Excluding the obvious just delete the braces manually)

Using C# in Visual Studio.

So instead of:

if (thingy is null)
{
    throw new ArgumentNullException(nameof(thingy));
}

Have the alternative:

if (thingy is null)
    throw new ArgumentNullException(nameof(thingy));

I have tried running CodeMaid and also changing the CodeCleanup (which just changes it back to having braces). I am happy to try any recommended Extensions etc to get this sorted.


Solution

  • This is not a standard refactoring in Visual Studio. But there are extensions that add this.

    Eg. Roslynator has its Remove Braces refactoring.