Utility to make C# code look pretty

  • Thread starter Thread starter Ed Debrot
  • Start date Start date
E

Ed Debrot

Nothing drives me crazier than having to look at someone's code where the
indentation is sloppy. Some lines are indented 2 spaces, others 10 spaces.
Sometimes there's 10 blank lines between lines of code, others times there's
none. Sometimes there are spaces around boolean operators, sometimes not.
Slopy, sloppy, sloppy! I try to get people to be neat and consistant, but it
doesn't help. Call me anal but I think neat code is a sign or organization
and pride in what you're coding. Is there any utility (maybe already in the
SDK) that can make pretty an existing C# module?

thanks!
 
I'll second that.

I use ReSharper as well, it's wonderful.
Has a menu option to "reformat code" to whatever coding style options you
have currently set.
 
Ed said:
Nothing drives me crazier than having to look at someone's code where the
indentation is sloppy. Some lines are indented 2 spaces, others 10 spaces.
Sometimes there's 10 blank lines between lines of code, others times there's
none. Sometimes there are spaces around boolean operators, sometimes not.
Slopy, sloppy, sloppy! I try to get people to be neat and consistant, but it
doesn't help. Call me anal but I think neat code is a sign or organization
and pride in what you're coding. Is there any utility (maybe already in the
SDK) that can make pretty an existing C# module?

thanks!

For me, the built-in Visual Studio indentation works pretty well. You
can download Visual C# 2005 Express for free that includes the same
great text editor as the full versions.

Just my opinion.
 
One trick of the IDE that people might have missed... (only works for a
single file at a time, though)

[Ctrl]+A, [Ctrl]+C, [Ctrl]+V

As in, "select all", "copy", "paste"; when the IDE pastes the code (over the
existing in this case), it reshapes it using "standard" indentation and
doing braces etc according to the user's current preferences. Not ideal, but
very quick.

After previous posts, I am now looking at reshaper, though ;-p

Marc
 
Now that's awesome. I really just wanted to get the spacing right and
sure enough you're solution was simple and easy. Thanks a lot! It even
added spaces where there were none in lines like

+=new ...

becase

+= new ...

and replaced spaces with tabs, provided that's how I had my editor
setup.

thanks again!
 
I think the credit here really has to go to the VS2005 development team.
Damned handy feature, though ;-p

Glad I could help,

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top