Visual Studio Formatting Problem

I use Visual Studio 2008. In my editor, whenever I write an automatic property, it “receives” and “sets” the wrappers on one line whenever I write “set” and put a semicolon (;). eg:

public string MyProperty { get; set; } 

I want it to be formatted as follows

 public string MyProperty { get; set; } 

Currently, I manually formatted it after writing. How can I set it as the default format?

Edit:

Options> Text editor> C #> Formatting> Wrap> Leave the block in one line is not already set for me.
I disabled all three options available in Options> Text Editor> C #> Formatting> General, but this will not work. Anything else?

+4
source share
5 answers

If you put everything 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> Wrapper> Leave the block in one line

If you really want to format it in your own way, you can disable:

Options> Text editor> C #> Formatting> General> Automatically format the completed block}

But you probably want to disable Automatically format the insert .

+7
source

If you are using ReSharper, Code Editing → C # → Formatting Style → Line Breaks and Wrapping has the option “Place abstract / auto property / indexer / event on single line” that controls the behavior you describe.

+1
source

Tools → Options → A text editor has many options for different languages ​​regarding how Visual Studio should (or should not) automatically format your code.

0
source

Look under Tools → Options → Text Editor → C # → Formatting.

You can find there a setting that will format it the way you want.

EDIT

This is a workaround, but it will be a trick.

Make a code snippet for automatic properties. Here is a link to more information on how to do this. This will require 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 other add-ons for creating code?

0
source

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

0
source

Source: https://habr.com/ru/post/1306836/


All Articles