I think some context is missing in this discussion. There isn't any
way to do what you want. And for good reason.
For example think about the case that you a couple of methods and
classes that are only called resp. instantiated by using reflection.
There's no telling which methods aren't used and which methods are in
general.
In the specific case that you have a "bounded application" with just a
couple of DLL's and executables you can try using code coverage or
other tests -- but that might prove to be problematic because not
every method has to be called during a test run.
So that leaves you just with one possible option: trying to figure out
the dependencies of a method by creating a program.
Perhaps I can help with a starting point. Let's assume you don't use
reflection. Then you can actually exploit reflection of .NET to find
assembly references:
1. use '<assembly>.GetReferencedAssemblies()'; push all those in a
dictionary and recurse.
2. compare the assemblies in the dictionary to the assemblies in the
directory. That leaves you with unused assemblies.
Furthermore you should notice that methods are usually called from
within classes. Ask every assembly for its types and iterate over all
methods. You will end up with a bunch of "MethodInfo" objects. Find
the "GetMethodBody" function and loop through the list of
"LocalVariables" and find the "LocalType" member of that. Combine that
with the parameter types, generic types, inheritance types and the
attribute types and you will get a list of all types that the method
uses (hope I'm not forgetting something...). Compare that to the types
you find in all assemblies. You will end up with the classes that
aren't used.
.... and to end up unleashing all hell I would try to parse the IL code
in the GetMethodBody function. After all, how hard can that be? :-)
(
http://www.chiramattel.com/george/blog/2004/08/16/
first_version_of_il_parser.html)
Perhaps it's easier to just leave the unused methods to rot where they
were in the first place...
Cheers,
Stefan.
P.S.: if you decide to turn to code coverage you can always try (free
trial) ANTS profiler, (free) CLR profiler, or the likes. While it does
way more than you want, you can deduce most of the information you
seek there as well.
On 20 apr, 19:56, Frank Rizzo <n...@none.comwrote:
Is there a setting in VS2005 to quickly locate methods that are unused
(maybe through compiler warnings)? If not, any utilities out there that
do that?
Thanks