开发者

How can I easily count the number of Forms in a large solution?

How can I easily count the number of Forms in a large solution?

I have Visual Studio solution containing 20+ winforms projects. I have to do a task where I have to inspect every form, and I have to give an effort estimate to my project lead. This estimate is best given in terms of the number of forms. It's useful to report pro开发者_C百科gress in terms of "27/275 forms done, spend 3 hours".

For this project, I use VS 2008 and Resharper 5.

A more general answer, for instance on "how to count the number of classes deriving from a specified class" would also be nice.


This is built into ReSharper - no code or extra tools needed. I don't have ReSharper 5 in front of me, but on version 4.5, I'd use the menu command under ReSharper > Search > Find Usages Advanced.

From there you can generate a list of all classes that inherit from System.Windows.Form. Then, either look at the list of search results in the IDE, or export it to a file for further inspection.


Here is a simple easy way which works if your projects are organised in a nice heirarchal way - open Windows File Explorer at the root of the solution, and do a search on file suffix, once the search is finished the count of files will be in the Explorer status bar at the bottom.

For classes that used C#, i could do a whole solution search for the text : MyBaseClass, in the Find window this would return all the classes which derived from whatever MyBaseClass i happened to nominate. I'm not sure of the syntax for R# but you should be able to do something similar.

Lastly, i believe ReSharper has a function for this, but it might be only available in the paid version.


I'd use Reflection for this, which will mean you will have to build the entire solution first.

Then make a list of all the assemblies, and then get all namespaces a described here.

Then you can get all the classes in a namespace, as described here.

It's fairly easy to check whether the type is derived from Form or not.

Hope this helps...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜