Solved

.Net C# code cleanup

Posted on 2009-05-04
5
530 Views
Last Modified: 2013-12-17
Ok so I've been adding to this C# class that I've written and over time its become totally unorganized.  I'm new to .net so I'm not sure if I can do this but is there a tool that does basic code cleanup.

Mainly what I want is to alphabetize all the functions and the classes local variables as my codes been getting less readable as things have been getting added and that would really help.  Anybody with any .Net experience have any ideas as to if .Net has a code cleanup function.  

I've seen the edit>format thing which works ok but I'm mainly after alphabetizing my functions and variables.
0
Comment
Question by:ICPooreman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 39

Accepted Solution

by:
abel earned 500 total points
ID: 24298038
This might do what you want, but I haven't tried it myself (though I know quite some people that were happy with it, it is a commercial product and I'm not sure you're after something like that): http://www.jetbrains.com/resharper/features/code_formatting.html
0
 
LVL 9

Expert Comment

by:tculler
ID: 24298230
My best advice would be to ditch alphabetizing your functions; that makes little sense, because you want to logically group your functions, not alphabetize them. If you're using Visual Studio (I surely hope you are, because it is truly the king of IDE's, especially for C#), I suggest using the #region and #endregion directives. Any code between these two directives can be collapsed, and the region can be labelled for easy use. For example, I have a custom code snippet that does the "skeleton" for this automatically, and it looks similar to the following:
namespace SomeNamespace
{
     public class SomeClass
     {
          #region Fields
          // ALL fields, public and private
          #endregion
 
          #region Construction
          // ALL overloaded constructors
          #endregion
 
          #region Properties
          // ALL properties
          #endregion
 
          #region Public Methods
          // Group each method and all overloads
          // in their own region.
          #region SomeMethod
          public void SomeMethod() {}
          public void SomeMethod(int someInt) {}
          public void SomeMethod(int someInt, string someString) {}
          #endregion
          // ALL public/internal methods, grouped as above
          #endregion
 
          #region Private Methods
          // ALL private/protected methods, grouped as above
          #endregion
 
          // Any other logical groupings, conforming to above.
     }
}

Open in new window

0
 
LVL 27

Expert Comment

by:nmarun
ID: 24298233
I was going to suggest Resharper as well. I've used this add-on for quite some time now and I'll be honest.. I cannot do without it now. It is really helpful and saves quite a bit of time.
0
 

Author Closing Comment

by:ICPooreman
ID: 31577685
Wow I just downloaded resharper... I've only been playing with it for several minutes but I'm already quite impressed.  Thanks this did the trick.
0
 
LVL 39

Expert Comment

by:abel
ID: 24298311
maybe I should download it too, if all of you are so enthusiastic about it ;-)

> Wow I just downloaded resharper... I've only been playing with it for
> several minutes but I'm already quite impressed. Thanks this did the trick.

glad it helped you so well. Like I said: I should try it myself perhaps to cleanup some customer's code ;-)

Don't forget on the comment of tculler: using regions is quite a good thing and can be more helpful then alphabetizing... But that depends on your need, of course.
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question