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 metho开发者_Go百科ds.
Thanks.
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.
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.
精彩评论