Matt Evans
Matt Evans

Reputation: 7575

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

Upvotes: 8

Views: 1426

Answers (2)

vicneanschi
vicneanschi

Reputation: 478

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.

Upvotes: 2

George Mamaladze
George Mamaladze

Reputation: 7931

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

Upvotes: 2

Related Questions