Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual studio formatting issue

I am using Visual Studio 2008. In my editor whenever I write an automatic property it's "get" and "set" wraps to a single line whenever I wrote "set" and put semicolon(;). like this:

public string MyProperty
{
    get; set;
}

I want it to be formatted like this

public string MyProperty
{
    get;
    set;
}

Currently I am manually formatting it to this after writing it. How can I set it as a default format?

Edit:

Options > Text Editor > C# > Formatting > Wrapping > Leave block on single line is already unchecked for me.
I unchecked all three option available in Options > Text Editor > C# > Formatting > General, but it doesn't work. Anything else?

like image 748
viky Avatar asked Feb 28 '23 05:02

viky


2 Answers

If you put it all on one line, the default formatting options will leave it alone:

public string MyProperty { get; set; }

This is controlled by:

Options > Text Editor > C# > Formatting > Wrapping > Leave block on single line

If you really want to format it your way, you could disable:

Options > Text Editor > C# > Formatting > General > Automatically format completed block on }

But you'd probably want to disable Automatically format on paste too.

like image 192
Igby Largeman Avatar answered Mar 08 '23 01:03

Igby Largeman


If you're using ReSharper, Code Editing -> C# -> Formatting Style -> Line Breaks and Wrapping has an option "Place abstract/auto property/indexer/event on single line" that controls the behavior you describe.

like image 41
Josh Avatar answered Mar 08 '23 02:03

Josh