Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Wednesday, October 1, 2008 11:03 AM
Hey Everyone,
Do any of you know any fast ways of getting rid of unused unreferenced code? Obviously I could check usages of each property - but surely there is a faster way?
Thanks,
All replies (4)
Wednesday, October 1, 2008 2:08 PM âś…Answered
There are a few issues with doing this.
Any public classes or methods and the internal, protected, and public methods can be accessed outside of the assembly, so even if you don't reference those methods within the assembly, the compiler may determine that you intended to expose these methods for use by other external assemblies that reference your assembly.
What about reflection? I use reflection sometimes in my code occasionally that references certain methods. Although right clicking and choosing "find all references" doesn't seem to find anything, I'm sometimes calling the code anyways. I find in those situations it's just better to write a comment in the method warning myself not to delete the method.
You could use tools such as Resharper to help you find these unused methods and properties. Again, it won't warn you on public methods or methods that could somehow be accessed from outside the assembly, but it's a start.
David Morton - http://blog.davemorton.net/
Wednesday, October 1, 2008 11:38 AM
Hi,
set the "Treat Warnings as errors" option to "all" in your project properties. You can find it the option on the "build" tab.
This will show unused properties, variables, methods etc. as errors.
Best Regards,
Ilija
Wednesday, October 1, 2008 11:44 AM
Thanks, but that only found a few usages - don't find Unused methods. Oh well, guess I will have to do it manually!
Wednesday, October 1, 2008 2:09 PM
OK thanks David