Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Visual Studio Format getter and setter on one line

I just scaffolded a project using Template Studio WinUI v5.3 and when I press Ctrl K D to format document, the getter and setter is placed on new lines.

current.cs

public class MyClass
{
    public string MyProp
    {
        get; set;
    }
}

I want:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

public class MyClass
{
    public string MyProp { get; set; }
}

The readability is bad for a class with many properties. I searched a lot through Visual Studio and I still can’t find the solution. The cause I suppose its related to a new C# version. My other projects use the same Visual Studio settings, but this formatting does not apply to them.
Do you know where can I find the setting for this problem?

Problem
I write a prop like this public int MyProperty { get; set; }, then after I press Ctrl K D it moves them on multiline format.

>Solution :

You can set this in your .editorconfig:

[*.cs]
csharp_preserve_single_line_blocks = true

Or you can set it directly in VS: Tools > Options > Text Editor > C# > Code Style > Formatting > Wrapping and check "Leave block on single line".

Image of the above setting

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading