Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a tool for finding unreferenced functions (dead, obsolete code) in a C# app? [closed]

I want to delete foo() if foo() isn't called from anywhere.

like image 529
Corey Trager Avatar asked Sep 15 '08 18:09

Corey Trager


People also ask

How do I find unused methods in C#?

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.


1 Answers

Gendarme will detect private methods with no upstream callers. It is available cross platform, and the latest version handles "AvoidUncalledPrivateCodeRule".

FxCop will detect public/protected methods with no upstream callers. However, FxCop does not detect all methods without upstream callers, as it is meant to check in the case that your code is part of a Library, so public members are left out. You can use NDepend to do a search for public members with no upstream callers, which I detail here in this other StackOverflow answer.

(edit: added information about Gendarme which actually does what the questioner asked)

like image 50
user7116 Avatar answered Oct 12 '22 19:10

user7116