tags:

views:

73

answers:

2

I have received a legacy .Net c# solution with many class library projects to review, re-factor and reuse. This solution is not used anywhere and lying in the code junkyard. The solution is compiling properly though.

There are 4 primary methods, that is needed from the main class library. I just want to retain all the subsequent classes, methods, properties used by these 4 methods from all the other projects in the solution and strip off all the other codes which is junk for me. Currently, i am going by manual tracing from these 4 main methods in Visual Studio 2010's "Call Hierarchy" feature.

Is there a automated process to quickly identify the related codes to my main methods and extract it to brand new shiny solution (which hopefully builds successfully) so that i just have to see the relevant code devoid of other codes that is not needed by my four main methods.

Thanks.

A: 

I find ReSharper pretty useful for detecting unreachable or unused code, so I'd certainly give that a go. You can download a demo version from http://www.jetbrains.com/resharper/.

It may not do everything for you, and finding unused code across multiple classes (in other words public methods that are not called) isn't so easy, but it's a good start.

Related to this, I would also advise you get a good set of unit tests in place before you undertake any refactoring, so that you can easily spot if/when you break functionality.

Steve Haigh
Currently none of the code is either unreachable or unused. Its just so that I wish to extract all the code relevant just to my main four methods as described above.
Ajit Singh
You descibed it as "junk", apologies for misinterpreting. As you remove code then you will find other code may become unreachable and can also be removed. And to whoever downvoted, thanks for that. This was a perfectly reasonable answer so I fail to see why I get a -1.
Steve Haigh
+3  A: 

Static tools are useful -- try NDepend -- but dynamic calls mean that any part of your codebase might be accessed by these methods. Try running a code coverage tool such as NCover with an extensive suite of unit tests, and perhaps manual tests as well, and then analyze the tool's output.

Joshua Fox