I am curious to know how many static methods and static classes we have in our Visual Studio 2013 solution. We have lots of projects in there...
Is there anything built in to Visual Studio that can do this? I cant see anything in the Code Metrics window that countsthis.
I know I can use a Ctrl+F to search for static class (bit trickier using RegEx for static class). Also this is tricky for methods. So I get 350 or so static classes.
The only other thought I have on this is something like writing my own reflection based check.
With ctrl-f and using "Look in: Entire Solution", you could just search with this regex for static methods
^\s*(public\s+|internal\s+|private\s+)?static\s+([a-zA-Z0-9_\<\>\.\:]+)\s+([a-zA-Z0-9_\<\>]+)\s*\(.*\)
and this for static classes
^\s*(public\s+|internal\s+|private\s+)?static\s+class
To be more confident of no false-positives you could limit the search to look only in *.cs files. At the bottom of "Find Results" you'll see "Matching lines:" with the count after it.
Limitations that I see:
(\r?\n)?
after every token in the regexes above.#ifdef 0
would not be detected. I don't think there's an easy way around this without parsing it more thoroughly with Roslyn (for example) or by compiling it and using reflection like you say in your question.