<p>I want to delete foo() if foo() isn't called from anywhere.</p>

[{'answer_id': 65602, 'author': 'Kent Boogaart', 'author_id': 5380, 'author_profile': 'https://Stackoverflow.com/users/5380', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://www.jetbrains.com/resharper/" rel="nofollow noreferrer">Resharper</a> does this, and not just with methods. It also does it with using statements, variables etcetera.</p>\n'}, {'answer_id': 65603, 'author': 'user7116', 'author_id': 7116, 'author_profile': 'https://Stackoverflow.com/users/7116', 'pm_score': 5, 'selected': True, 'text': '<p><a href="http://www.mono-project.com/Gendarme" rel="nofollow noreferrer">Gendarme</a> will detect private methods with no upstream callers. It is available cross platform, and the latest version handles "<a href="http://www.mono-project.com/Gendarme.Rules.Performance" rel="nofollow noreferrer">AvoidUncalledPrivateCodeRule</a>".</p>\n\n<p><a href="http://msdn.microsoft.com/en-us/library/bb429476(VS.80).aspx" rel="nofollow noreferrer" title="FxCop">FxCop</a> 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. <a href="https://stackoverflow.com/questions/71518/is-there-a-custom-fxcop-rule-that-will-detect-unused-public-methods#71929">You can use NDepend to do a search for public members with no upstream callers, which I detail here in this other StackOverflow answer</a>.</p>\n\n<p><em>(edit: added information about Gendarme which actually does what the questioner asked)</em></p>\n'}, {'answer_id': 65608, 'author': 'Scott Dorman', 'author_id': 1559, 'author_profile': 'https://Stackoverflow.com/users/1559', 'pm_score': 2, 'selected': False, 'text': '<p>Yes, the <a href="http://www.mztools.com/index.aspx" rel="nofollow noreferrer">MZ-Tools</a> addin has a review dead code feature.</p>\n'}, {'answer_id': 65617, 'author': 'RedDeckWins', 'author_id': 1646, 'author_profile': 'https://Stackoverflow.com/users/1646', 'pm_score': 2, 'selected': False, 'text': '<p>Well, if VS doesn\'t do this natively, a simple method is to right click on the method and select "find all references" .  If there is only 1 reference (where it is declared) it most likely isn\'t used anywhere else.</p>\n'}, {'answer_id': 65740, 'author': 'Helen Toomik', 'author_id': 9449, 'author_profile': 'https://Stackoverflow.com/users/9449', 'pm_score': 3, 'selected': False, 'text': '<p>Bear in mind that Resharper (and probably other similar tools as well) will not highlight unused methods if the methods are marked <code>public</code>. There is no way a static code analysis tool will be able to check whether the methods of your assembly are used by other assemblies outside your solution. So the first step in weeding out unused methods is to reduce their visibility to <code>private</code> or <code>internal</code>.</p>\n'}, {'answer_id': 66046, 'author': 'Ian Nelson', 'author_id': 2084, 'author_profile': 'https://Stackoverflow.com/users/2084', 'pm_score': 3, 'selected': False, 'text': '<p><a href="http://www.ndepend.com" rel="nofollow noreferrer">NDepend</a> will also report on potentially unused code.</p>\n'}, {'answer_id': 3968758, 'author': 'Patrick from NDepend team', 'author_id': 27194, 'author_profile': 'https://Stackoverflow.com/users/27194', 'pm_score': 2, 'selected': False, 'text': '<p>The tool <a href="http://www.NDepend.com" rel="nofollow">NDepend</a> can help find unused code in a .NET code base. <em>Disclaimer: I am one of the developer of this tool.</em></p>\n\n<p>NDepend proposes to write <a href="http://www.ndepend.com/Features.aspx#CQL" rel="nofollow">Code Rule over LINQ Query (CQLinq)</a>. Around <a href="http://www.ndepend.com/DefaultRules/webframe.html" rel="nofollow">200 default code rules</a> are proposed, 3 of them being dedicated to <em>unused/dead code</em> detection:</p>\n\n<ul>\n<li><a href="http://www.ndepend.com/DefaultRules/webframe.html?Q_Potentially_dead_Types.html" rel="nofollow">Potentially dead Types</a> (hence detect unused class, struct, interface, delegate...)</li>\n<li><a href="http://www.ndepend.com/DefaultRules/webframe.html?Q_Potentially_dead_Methods.html" rel="nofollow">Potentially dead Methods</a></li>\n<li><a href="http://www.ndepend.com/DefaultRules/webframe.html?Q_Potentially_dead_Fields.html" rel="nofollow">Potentially dead Fields</a></li>\n</ul>\n\n<p>NDepend is integrated in Visual Studio, thus these rules can be <a href="http://www.ndepend.com/Doc_VS_CQL.aspx" rel="nofollow">checked/browsed/edited right inside the IDE</a>. The tool can also be integrated into your CI process and it can build <a href="http://www.ndepend.com/SampleReports.aspx" rel="nofollow">reports</a> that will show rules violated and culprit code elements.</p>\n\n<p>If you click these 3 links toward the source code of these rules, you\'ll see that the ones concerning types and methods are a bit complex. This is because they detect not only unused types and methods, but also types and methods used <em>only</em> by unused dead types and methods (recursive).</p>\n\n<p>This is <em>static analysis</em>, hence the prefix <em>Potentially</em> in the rule names. If a code element is used <em>only</em> through reflection, these rules might consider it as unused which is not the case. </p>\n\n<p>In addition to using these 3 rules, I\'d advise measuring code coverage by tests and striving for having full coverage. Often, you\'ll see that code that cannot be covered by tests, is actually <em>unused/dead</em> code that can be safely discarded. This is especially useful in complex algorithms where it is not clear if a branch of code is reachable or not.</p>\n'}]
['https://Stackoverflow.com/questions/65585', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/9328/']