Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio/C# auto-format. Can I control newline after attributes

Tags:

Visual studio keeps doing this:

[DataContract]  public class MyContract  {     [DataMember]     public bool MyBool { get; set; }     [DataMember]     public string MyString { get; set; }  } 

I would like this:

[DataContract]  public class MyContract  {     [DataMember] public bool MyBool { get; set; }     [DataMember] public string MyString { get; set; }  } 

No big deal if the 'public class MyContract' is on the same line as the [DataContract].

Visual studio seems to have a lot of detailed autoformatting options, but I can't find any regarding newlines after attributes. Am I missing something here? Or is it just not available.

EDIT: At very least, I'd like a "don't change what I entered" formatting option, as opposed to a "always insert" or "always remove" newline option. It's super-annoying that it keeps unformatting my code after I type.

like image 615
Clyde Avatar asked Dec 10 '09 13:12

Clyde


People also ask

Can I use Visual Studio for C?

The Microsoft C/C++ for Visual Studio Code extension supports IntelliSense, debugging, code formatting, auto-completion. Visual Studio for Mac doesn't support Microsoft C++, but does support . NET languages and cross-platform development.

Is Visual Studio C or C++?

The Visual Studio IDE supports C++ development on Windows, Linux, Android and iOS with a code editor, debugger, test frameworks, static analyzers, and other programming tools.


1 Answers

What I usually do is hit Ctrl-Z the very moment autoformat jumps in where I don't appreciate it.

I.e., on a closing accolade, which formats a whole class or method. Type the closing accolade, see it changing the way you don't like it and then hit Ctrl-Z. (I know you were looking for an actual option, I don't know if any exists).

like image 122
Abel Avatar answered Sep 23 '22 13:09

Abel