views:

606

answers:

4

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.

+3  A: 

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

Abel
oh! that's actually not too bad. I always kind of assumed that would delete my last actual typing, but you obviously have realized that it doesn't.If there turns out to be no way to do a real configuration, this is a reasonable workaround
Clyde
Different programs act differently here. OpenOffice (personal favorite) for instance removes both autoformat *and* last typing, which is a nuisance. In Eclipse it depends on the plugin (often totally ruining the undo-list). Most Microsoft products (Visual Studio, Office) add it as an extra entry in the undo-list. Once you get used to it, it's not so bad indeed ;-)
Abel
A: 

I'm not sure myself, but have you looked at extras->options->text-editor->c#->formatting ? Therer are a few options which will probablry help you to get the desired effect.

Holger Kretzschmar
I've looked and don't see any
Clyde
Which visual studio version do you use? VS 6, 2003, 2005, 2008?
Holger Kretzschmar
Visual Studio 2008
Clyde
A: 

Not sure if it works for attributes, but look under Tools -> Options -> Text Editor -> C# -> Formatting -> Wrapping -> Leave block on single line or Leave statements and member declarations on the same line.

Agent_9191
No...already have those checked. They do not apply to attributes
Clyde
A: 

Yeah, Ctrl+E, D is your friend. You can optimize the formatting in Text editor options

Jay Zeng