How do I find usages of a method with a params argument such that the argument is not empty?
c#, c#-4.0, il, parameters, reflection
Solution
One simple way:
- Add an overload which doesn't take any parameters.
- Rebuild - the new overload will be used in preference to the `params` one
- Use whatever refactoring tools you normally use to rename the parameterless overload
- Count the calls with a simple "find"
- Discard all the code changes :)
Problem
I have a method in which its last argument is `params string[]`. I wish to search an assembly and count the number of usages in which the `params` argument is passed with at least one value. There are several hundreds of calls to this method, most of which do not pass in anything to this last `params` argument, so using something like ReSharper’s Find Usages and counting those usages which do not pass in anything to the `params` argument is not practical. How would I do this using reflection/disassembly? Or, is there a tool that could do this?