Good C# Code Beautifier?
am 23.10.2007 21:44:47 von Chris Mullins
We've got a lot of code we're about to migrate from .Net 1.1 to .Net 3.5.
This code has, shall we say, a somewhat organic coding style. I would like
to run all the code thorugh a C# Beautifier that complies with the Microsoft
standards for formatting and such. I'm not looking to change variable names,
but I want a consistant style throughout in terms of indenting, spacing, and
the like.
So far, I've played with several beautifiers, none of which did a very good
job on our codebase:
- GreatCode didn't really do well at all with our C# codebase
- UnCrustify did an alright job, but seems to be very bug prone. It misses
many common cases and seems to hit others. I spent an hour getting the
options just right, only to have the options not work 1/2 the time.
- SourceFormatX did an ok job, but again, missed alot of common cases that
the options were defined to hit.
- Resharper's built-in Formatter does a great job, but seems to crash alot
with an OutOfMemoryException on our bigger files. (Did I mention the source
code is, um, organic. As in, "Grown and Grown, often in unpredictable
directions").
- Visual Studio does a lousy job.
Any suggestions for a really good C# source code formatter?
--
Chris Mullins
Re: Good C# Code Beautifier?
am 23.10.2007 22:02:31 von mvp
Chris,
It might be a bit of a stretch, but I would say write your own. You
could use the classes in the System.CodeDom namespace to parse your code
into a CodeDom structure, and then output it in the way that you want.
--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
"Chris Mullins [MVP - C#]" wrote in message
news:uU$dO0aFIHA.1212@TK2MSFTNGP05.phx.gbl...
> We've got a lot of code we're about to migrate from .Net 1.1 to .Net 3.5.
>
> This code has, shall we say, a somewhat organic coding style. I would like
> to run all the code thorugh a C# Beautifier that complies with the
> Microsoft standards for formatting and such. I'm not looking to change
> variable names, but I want a consistant style throughout in terms of
> indenting, spacing, and the like.
>
> So far, I've played with several beautifiers, none of which did a very
> good job on our codebase:
> - GreatCode didn't really do well at all with our C# codebase
>
> - UnCrustify did an alright job, but seems to be very bug prone. It misses
> many common cases and seems to hit others. I spent an hour getting the
> options just right, only to have the options not work 1/2 the time.
>
> - SourceFormatX did an ok job, but again, missed alot of common cases that
> the options were defined to hit.
>
> - Resharper's built-in Formatter does a great job, but seems to crash alot
> with an OutOfMemoryException on our bigger files. (Did I mention the
> source code is, um, organic. As in, "Grown and Grown, often in
> unpredictable directions").
>
> - Visual Studio does a lousy job.
>
> Any suggestions for a really good C# source code formatter?
>
> --
> Chris Mullins
>
Re: Good C# Code Beautifier?
am 24.10.2007 07:38:36 von Andrew Faust
> - Resharper's built-in Formatter does a great job, but seems to crash
> alot with an OutOfMemoryException on our bigger files. (Did I mention the
> source code is, um, organic. As in, "Grown and Grown, often in
> unpredictable directions").
I had this same issue with Resharper on some code we migrated from 1.1 to
2.0 a while ago. It turned out it was just due to quantity of code in some
of our forms. .Net 1.1 didn't split out designer code from business logic
in to partial classes. We found that by taking the larger forms and
splitting them out manually we could run the code reformatter on the
individual files just fine.
We also hit this issue on a couple of files where we had multiple similar
classes in the same file. Bad coding standard in it's own right. We were
able to use Resharpers Refactor->Move command to quickly and easily move
the individual classes in to their own files and run the reformatter on
them at that point.
Kind of a pain, but it was worth it.
--
Andrew Faust
andrew[at]andrewfaust.com
http://www.andrewfaust.com
"Chris Mullins [MVP - C#]" wrote in message
news:uU$dO0aFIHA.1212@TK2MSFTNGP05.phx.gbl...
> We've got a lot of code we're about to migrate from .Net 1.1 to .Net 3.5.
>
> This code has, shall we say, a somewhat organic coding style. I would
> like to run all the code thorugh a C# Beautifier that complies with the
> Microsoft standards for formatting and such. I'm not looking to change
> variable names, but I want a consistant style throughout in terms of
> indenting, spacing, and the like.
>
> So far, I've played with several beautifiers, none of which did a very
> good job on our codebase:
> - GreatCode didn't really do well at all with our C# codebase
>
> - UnCrustify did an alright job, but seems to be very bug prone. It
> misses many common cases and seems to hit others. I spent an hour getting
> the options just right, only to have the options not work 1/2 the time.
>
> - SourceFormatX did an ok job, but again, missed alot of common cases
> that the options were defined to hit.
>
> - Resharper's built-in Formatter does a great job, but seems to crash
> alot with an OutOfMemoryException on our bigger files. (Did I mention the
> source code is, um, organic. As in, "Grown and Grown, often in
> unpredictable directions").
>
> - Visual Studio does a lousy job.
>
> Any suggestions for a really good C# source code formatter?
>
> --
> Chris Mullins
>