Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Identifying unused classes / controls / pages

We have a 10+ years old ASP.NET website project, with lots of unused / legacy user controls and pages.

Is there a tool which can assist in the process of identifying these elements of the solution, so we could refactor them out?

I know the issue is complicated because not all types are referenced as types which a compiler / tool might recognize. e.g. objects instantiated by reflection are instantiated using a string representing the class name. In addition asp.net pages are generally not referenced as types, but as page identifier strings in markup.

It still seems like someone would have created a tool which handles these cases and creates a candidate list of unused classes / pages / user controls

like image 219
Matt Evans Avatar asked Nov 29 '11 12:11

Matt Evans


2 Answers

You may use this regex to find unused registered controls

<%@\s*Register\s+TagPrefix\s*=\s*"(?<tagprefix>[^"]+)"\s+TagName\s*=\s*"(?<tagname>[^"]+)"\s+Src\s*=\s*"[^"]+"\s*%>(?!.*?\k<tagprefix>:\k<tagname>\s+)

I used powergrep to run this regex. The "Dot matches newline" checkbox should be enabled to work properly.

like image 109
vicneanschi Avatar answered Oct 01 '22 19:10

vicneanschi


ReSharper is a refactoring tool which might help you to identify clouds of unused classes and methods. It can also delete them safely. It allows you to delete a method or class and adjust all it's usages. See: Safe delete

It has also appropriate support of ASP.NET. See: ASP.NET support

like image 37
George Mamaladze Avatar answered Oct 01 '22 18:10

George Mamaladze