viky
viky

Reputation: 17689

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?

Upvotes: 4

Views: 3812

Answers (5)

Kevin Pilch
Kevin Pilch

Reputation: 11615

Note - I believe this was https://github.com/dotnet/roslyn/issues/2837 and fixed in VS2015 Update 1.

Upvotes: 0

Josh
Josh

Reputation: 662

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.

Upvotes: 1

NitroxDM
NitroxDM

Reputation: 5131

Look under Tools -> Options -> Text Editor -> C# -> Formatting.

You might find a setting there that will format it how you want.

EDIT

This is a workaround, but it would do the trick.

Make a code snippet for automagic properties. Here is link with more info on how to do that. It will need a little modification, but you can handle it. ;)

http://msmvps.com/blogs/kevinmcneish/archive/2007/04/30/property-code-snippet-for-visual-studio-2005.aspx

Do you have coderush or any other code generating addons installed?

Upvotes: 0

Jason Williams
Jason Williams

Reputation: 57942

Tools -> Options -> Text editor has a lot of options for various languages as to how Visual Studio should (or should not) auto-format your code.

Upvotes: 0

Igby Largeman
Igby Largeman

Reputation: 16747

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.

Upvotes: 7

Related Questions