views:

261

answers:

3

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?

+3  A: 

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.

Charles
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?
viky
If you unchecked all three options in Text Editor > C# > Formatting > General, and the editor is still automatically formatting your code as you type, then you must have an Add-in installed which is doing the formatting. Have a look under Tools > Add-in Manager.
Charles
A: 

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.

Jason Williams
I know that it is here but I am not getting which option to set?
viky
Under Languages, go to C#, then Formatting. Play with the options - there are previews that will help. Possibly Wrapping (Leave block on single line, Leave statements and member declarations on same line) will help. Or in General, disable the "automatically format..." options (though that is somewhat more drastic). You need to try the options for yourself to find a balance that you like.
Jason Williams
... For me, the formatting stays as I put it. If, on the other hand, you want it to automatically split the line for you instead of you having to press enter once(?) then perhaps you would be better off adding a code snippet for the auto-property body to save you typing all of it in every time.
Jason Williams
D'oh! I didn't see your comment about adding a code snippet after I change my answer.
NitroxDM
A: 

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?

NitroxDM
I know that it is here but I am not getting which one to set?
viky