DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: Detect unused code (C#)  (Read 12,433 times)

Ruffnekk

  • Uhm yeah...
  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 332
    • Programming School - Stage 1 Medal
    • Programming School - Deluxe Bonus Medal
    • Participated in NANY Challenge Once
    • Linux User
Detect unused code (C#)
« on: March 08, 2007, 07:29 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?
Regards,
RuffNekk

Programming is an art form that fights back.

PhilKC

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

PhilKC
It's not a bug, it's an undocumented and unexplainable feature.
Stick it on your site:

Ruffnekk

  • Uhm yeah...
  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 332
    • Programming School - Stage 1 Medal
    • Programming School - Deluxe Bonus Medal
    • Participated in NANY Challenge Once
    • Linux User
Re: Detect unused code (C#)
« Reply #2 on: March 08, 2007, 10:37 AM »
And to think I already have FXCop installed  :-[ Thanks PhilKC!  :P
Regards,
RuffNekk

Programming is an art form that fights back.

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,931
    • Gathering Badge
    • Plugin Coding Medal
    • Participated in NANY Challenge Seventeen Times
    • Cody Award
    • Coding Snacks
    • Volunteers/Staff
Re: Detect unused code (C#)
« Reply #3 on: March 08, 2007, 11:22 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

  • Uhm yeah...
  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 332
    • Programming School - Stage 1 Medal
    • Programming School - Deluxe Bonus Medal
    • Participated in NANY Challenge Once
    • Linux User
Re: Detect unused code (C#)
« Reply #4 on: March 08, 2007, 12:39 PM »
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 ;)
Regards,
RuffNekk

Programming is an art form that fights back.

Original address: https://www.donationcoder.com/forum/index.php?topic=7694.0