How do I find dead code in a Visual Studio 2008 C# project? Like unused classes, unused variables or unused resources?
What is the use of default keyword in C#? Is it introduced in C# 3.0 ?
How do I find dead code in a Visual Studio 2008 C# project? Like unused classes, unused variables or unused resources?
You can try FxCop, which is integrated in Visual Studio 2008 by the name of Code Analysis. You just have to right click the project file and Run Code Analysis .
FxCop is an application that analyzes managed code assemblies (code that targets the .NET Framework common language runtime) and reports information about the assemblies, such as possible design, localization, performance, and security improvements.
The active rules can be configured in the Code Analysis section of the project properties. For example some rules relevant to the case in hand are present in Usage Rules and Performance Rules:
And for greater flexibility you also write your own custom rules (Tutorial on writing your own Code Analysis rule).
Install JetBrains ReSharper which will highlight the unused code for you.
A very useful tool for this is the NDepend dependency analysis tool. You can load your Visual Studio project into this, and it will analyse the dependencies of all your assemblies, types and methods. It gives you a wealth of information on the dependenices, including (but in no way limited to!) methods/types that are not used by anything at all.
You can view the dependencies either graphically, or in a list, and can write your own custom dependency queries such as this - a simple CQL query show potentially unused methods :
SELECT
METHODS // Get me a list of methods
WHERE
MethodCa == 0 // Where their afferent coupling is zero, (afferent coupling being the number of other methods that call it)
A highly recommended tool.
Shift + F12 in VS is useful for a quick check :)
While I wouldn t recommend this for a large code base you can do a certain amount manually.
If you right click over a method or class and then select "Find Usages" you ll get an output of all places where it s referenced. Obviously this will be empty if it s not used.
For ongoing clean up I d install ReSharper
What is the use of default keyword in C#? Is it introduced in C# 3.0 ?
I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...
I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...
I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...
I have two EF entities. One has a property called HouseNumber. The other has two properties, one called StartHouseNumber and one called EndHouseNumber. I want to create a many to many association ...
How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...
Since I cannot order my dictionary, what is the best way of going about taking key value pairs and also maintaing an index?
Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...