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 opt开发者_如何学Pythonion available in Options > Text Editor > C# > Formatting > General, but it doesn't work. Anything else?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.
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.
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.
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?
Note - I believe this was https://github.com/dotnet/roslyn/issues/2837 and fixed in VS2015 Update 1.
精彩评论