I have to refactor a large C# Application, and i found a lot of functions that are never used in the app. Is there a tool that can check for unused code, so i can remove all the unused functions?
ReSharper does a great job of finding unused code.
In the VS IDE, you can right click on the definition and choose 'Find All References', although this only works at the solution level.
It's a great question, but be warned that you're treading in dangerous waters here. When you're deleting code you will have to make sure you're compiling and testing often.
One great tool come to mind:
NDepend - this tool is just amazing. It takes a little while to grok, and after the first 10 minutes I think most developers just say "Screw it!" and delete the app. Once you get a good feel for NDepend, it gives you amazing insight to how your apps are coupled. Check it out: http://www.ndepend.com/. Most importantly, this tool will allow you to view methods which do not have any direct callers. It will also show you the inverse, a complete call tree for any method in the assembly (or even between assemblies).
Whatever tool you choose, it's not a task to take lightly. Especially if you're dealing with public methods on library type assemblies, as you may never know when an app is referencing them.
Resharper is good for this like others have stated. Be careful though, these tools don't find you code that is used by reflection, e.g. cannot know if some code is NOT used by reflection.
The truth is that the tool can never give you a 100% certain answer, but coverage tool can give you a pretty good run for the money.
If you count with comprehensive unit test suite, than you can use test coverage tool to see exactly what lines of code were not executed during the test run. You will still need to analyze the code manually: either eliminate what you consider dead code or write test to improve test coverage.
One such tool is NCover, with open source precursor on Sourceforge. Another alternative is PartCover.
Check out this answer on stackoverflow.
Yes, ReSharper does this. Right click on your solution and selection "Find Code Issues". One of the results is "Unused Symbols". This will show you classes, methods, etc., that aren't used.
And you don't have to buy NDepend.
As pointed Jeff the tool NDepend can help to find unused methods, fields and types. To elaborate a bit, this can be done thanks to the 3 following CQL (Code Query Language) queries. These 3 queries can be customized to your exact need. Notice also how these queries are prefixed with WARN IF Count > 0 IN, that transform them from CQL queries to CQL rules. These CQL rules can be checked in your CI environment, or even, interactively in VS itself while you are coding:
// <Name>Potentially unused methods</Name>
WARN IF Count > 0 IN SELECT METHODS WHERE
MethodCa == 0 AND // Ca=0 -> No Afferent Coupling -> The method is not used in the context of this application.
!IsPublic AND // Public methods might be used by client applications of your assemblies.
!IsEntryPoint AND // Main() method is not used by-design.
!IsExplicitInterfaceImpl AND // The IL code never explicitely calls explicit interface methods implementation.
!IsClassConstructor AND // The IL code never explicitely calls class constructors.
!IsFinalizer AND // The IL code never explicitely calls finalizers.
!IsVirtual AND
!IsEventAdder AND
!IsEventRemover
// <Name>Potentially unused types</Name>
WARN IF Count > 0 IN SELECT TYPES WHERE
TypeCa == 0 AND // Ca=0 -> No Afferent Coupling -> The type
// is not used in the context of this application.
!IsPublic AND // Public types might be used by client applications of
// your assemblies.
!NameIs "Program"
// <Name>Potentially unused fields</Name>
WARN IF Count > 0 IN SELECT FIELDS
WHERE
FieldCa == 0 AND // Ca=0 -> No Afferent Coupling -> The field is not used in the context of this application.
!IsPublic AND // Although not recommended, public fields might be used by client applications of your assemblies.
!IsLiteral AND // The IL code never explicitely uses literal fields.
!IsEnumValue AND // The IL code never explicitely uses enumeration value.
!NameIs "value__" // Field named 'value__' are relative to enumerations and the IL code never explicitely uses them."