Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • May 27, 2017, 04:49:50 AM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Detect unused code (C#)  (Read 7357 times)

Ruffnekk

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 332
    • View Profile
    • Donate to Member
Detect unused code (C#)
« on: March 08, 2007, 01:29:43 AM »
I am looking for a tool/trick/technique to detect any unused methods/functions in my C# application. It's quite a large application (Argus) and it has over 37 code files, totalling about 25000 lines of code. I want to run a tool or something to see if I have any code that is unused (never called). When I'm coding I'm in another mindstate and tend to forget to delete subs or functions I don't need anymore. I organize my code into regions and comments them, but still it's a tedious job to do this manually... Using "Find all references" has helped me already, but that's not very useful if one unused method calls another unused method and so on... Any ideas about this?

PhilKC

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 117
    • View Profile
    • Donate to Member
Re: Detect unused code (C#)
« Reply #1 on: March 08, 2007, 04:33:25 AM »
FXCop can do that, I think..
http://www.gotdotnet.com/Team/FxCop/

PhilKC

Ruffnekk

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 332
    • View Profile
    • Donate to Member
Re: Detect unused code (C#)
« Reply #2 on: March 08, 2007, 04:37:09 AM »
And to think I already have FXCop installed  :-[ Thanks PhilKC!  :P

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 37,062
    • View Profile
    • Donate to Member
Re: Detect unused code (C#)
« Reply #3 on: March 08, 2007, 05:22:57 AM »
By the way, this is called "code coveragew" analysis in the world of program analysis/optimization/debugging, and is used often to make sure that all of the code is tested thoroughly.

Ruffnekk

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 332
    • View Profile
    • Donate to Member
Re: Detect unused code (C#)
« Reply #4 on: March 08, 2007, 06:39:45 AM »
Thanks for the info mouser.

I'm now checking the assemblies with FxCop and so far I had over 1000 issues, which I will solve before 1.0 comes out :D. Good learning practice and very useful! I just hadn't thought about it before until PhilKC reminded me ;)