Ed Sinek
Ed Sinek

Reputation: 4977

Search through code for list of unique controls

Does anyone have a nice way to search through a WebForms web app to return the list of unique user controls used throughout the app (in .aspx and .ascx pages)? We've got 100+ pages and 150+ user controls. We are also using a few third party libraries and I want to see which controls we are using across the app. I'm not necessarily looking for a count of each unique control, just the unique items. For example: asp:Label, asp:MultiView, etc.

Thanks in advance.

Upvotes: 1

Views: 80

Answers (1)

Alexander Manekovskiy
Alexander Manekovskiy

Reputation: 3203

I'm using NDepend when it comes to dependencies analysis and changes analysis. If you don't have licence trial version should allow you to use all features without restrictions.

Start from creation of the new project and add compiled assembly of your web application. It will automatically load all dependencies which you can browse with Class Browser. This will give you the basic understanding of what types (controls) are used by your web app.

NDepend Class Browser

Also you can narrow or extend your findings with Queries and Rules Edit (Ctrl+Alt+R). Run following query to get a list of used controls from System.Web.UI.WebControls:

from type in Assemblies.WithNameNotIn("WebApplication2").ChildTypes()

// depth is needed th find all controls that are used directly or indirectly
let depth = type.DepthOfIsUsedBy("WebApplication2".MatchAssembly())

// we are interested only in types from specific namespace, in this case "System.Web.UI.WebControls"
where type.ParentNamespace.Name == "System.Web.UI.WebControls"

where depth  >= 0 orderby depth
select new { type, depth }

CQL query result

As you can see query result could be exported various formats (HTML, Excel, Text or Graph).

NDepend is very powerful tool mostly because of built in Code Query Language. It is based on the LINQ and you can start creating simple queries without any additional training or learning.

Upvotes: 1

Related Questions