Search code examples
c#visual-studio-2022editorconfig

VS 2022 Style Rule to keep Auto-Implemented Properties on One Line


When I cut & paste the following C# text in VS 2022:

public int? Units { get; set; }

it pastes it formatted as:

public int? Units
{
    get; set;
}

What .editorconfig rule needs to be adjusted to tell VS that I want my auto-implemented properties to remain on a single line?

Also, for heartfelt bonus points (but no actual points), is there a good way of finding this information myself? I googled this until my eyes bled, and I searched the options under Options -> Text Editor -> C# -> Code Style for as long as I could, with no luck.


Solution

  • In the .editorconfig UI, it is:

    Whitespace -> Wrapping preferences -> Leave block on single line (checked)
    

    In the .editorconfig file, add:

    csharp_preserve_single_line_blocks = true
    

    While this question is now answered, I still find myself frustrated trying to figure out how to find these options in these instances when I can't think of the right word or phrase to search by. To a certain extent it just requires luck, which does not make for a happy code monkey.