Reputation: 4240
How do you find all the empty methods of a specific type defined in a project? an example use case would be to find all empty Page_Load methods defined in an Asp.Net application.
Upvotes: 4
Views: 1999
Reputation: 31
to improve ravinsp's answer a bit, if you want the 'find all' to actually hilight the entire method (so you can do a search and replace to remove them), use regex
^.*void\ .*\(*\)(\ |(\r\n))*{(\ |(\r\n))*}
Upvotes: 1
Reputation: 69362
You could use FxCop (or possibly StyleCop) to detect empty methods. An FxCop rule for detecting empty methods can be found here (although I haven't tested it, you should be able to modify it to avoid removing the methods).
Upvotes: 0
Reputation: 4240
In the visual studio find-tool, set it to use Regular Expressions. Use this expression to find empty methods.
void\ .*\(*\)(\ |(\r\n))*{(\ |(\r\n))*}
To find empty Page_Load methods:
void\ (Page_Load).*\(*\)(\ |(\r\n))*{(\ |(\r\n))*}
All these approaches would work for "void" methods. For other types, you can change the expression or further generalize the expression to match any kind of return type.
Upvotes: 8