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

Clyde picture Clyde · Dec 10, 2009 · Viewed 8.5k times · Source

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.

Answer

Abel picture Abel · Dec 10, 2009

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).