Find Non Used Functions? - c#

I know you can perform a 'Find All References' on a function and you can determine if it is being used anywhere, but is there a tool that will go through all of my functions and highlight any that are not called anywhere in the code?

I believe ReSharper can do what you want. More specifically, the Safe Delete command should at least faciliate the job. Although I haven't tried it, the Code Cleanup tool may well do the whole thing automatically.

I prefer ReSharper for this, but if you're looking for a free product, Microsoft FxCop will identity unused public methods.

Related

How to rename refactor all private member variable variables in a C# VS 2013 project?

I am using camelCase convention for private member variables in my C# projects. Because of changed code quality requirements now I "have to"/"would like to" rename/refactor all these members to _camelCase.
For example logger will be _logger.
Additional info:
1) I definitely know that a particular rename/refactor could cause error, and an interactive refactor tool will warm me in that case. Still I want to automate mass rename, I'll take the risk ending with not compilable source what needs manual corrections.
2) I use latest ReSharper if this helps, but still I can not figure solution for my task. (To be clear I do not suggest ReSharper should be the solution, just a possibility.
Thanks in advance
There is a guy called Steve Cadwallader who has made a visual studio extension called "CodeMaid" (http://www.codemaid.net/). It has several things you can use for cleaning up code etc and the source code is free i think. If you have strict code quality requirements like this maybe its worth it to download his extension and do a slight modification to it. I know it already do stuff with private member variables so it shouldnt be too hard to modify.
This extension can do stuff on a file or project basis which makes it easy for you if you have a large number of files to modify.
One easy way of doing this is to just you Ctrl + F & Find and replace. This however doesn't give you the security that you have only updated the relevant variables and could end up changing other thing. But you can always undo the changes easily if they cause problems.
UPDATE
Having read other answers I have tried Ctrl + R + R and this is now the way I will be doing things. I would up vote that answer but can't as I don't have enough reputation yet!
The only way I found is via the Resharper's "Show Potential Fixes" Menu option as outlined by Jowen here.
How to reformat naming styles with ReSharper?

Comment template in VS2010

I have inherited an API which doesn't have proper comments, and I am working on changing that.
Anyone know if there is some sort of mechanism to add a default XML comments to all the members of a class or an assembly?
(I remember seeing something like that on a webcast and I think he might have used PowerShell script to achieve that.)
This way I can avoid lots of repetitive steps, and have everything in place to go and start writing just the comments.
Anyone has any better suggestions?
GhostDoc is pretty fantastic for XML documentation, although you'll need to purchase a copy to generate automatic documentation for all classes/members. The free version allows you to right click (or use a hotkey) on class or member and it will generate the documentation.
I've found GhostDoc to be pretty good.
Once you've run it over your code you then simply add details where required.
http://submain.com/products/ghostdoc.aspx

Is there a way to make the C# compiler issue a warning when instance variable is hidden(shadowed)?

I am refactoring a little bit of code and I think I have created some instance variables that are being hidden(shadowed) in older methods. I want to see a warning wherever the hiding(shadowing) happens so I can check to make sure that it's actually what I want (and it's hardly ever what I want). Is there any easy way to do that?
If you run Code Analysis, that'll show up (as CA1500 from the Maintanability section).
Have you looked into any productivity tools such as Resharper? http://www.jetbrains.com/resharper/
It will find that (and probably proactively warn you) with very little effort on your part.
No there is no way to make the C# compiler emit this warning.

C# Object/Class-Debugging-Library (to HTML/String)

Does anybody know a class, that writes the structure(public (static, instance) members)/data of an object/class to string (for debugging-purposes) or even generate fancy html-divs or something like that?
Well, the obvious answer is to use the debugger build into Visual Studio, it has some wonderful tools (Watches, Quick Watch, Immediate window, etc...) If for some reason you dont have access to the debugger, I suggest you fix whatever it keeping you from it, but otherwise you can write yourself a fairly robust object dumper using Reflection. Or you can take Eric White's advice and use the ObjectDumper.
Check out: http://blogs.msdn.com/ericwhite/archive/2008/08/14/object-dumper-an-invaluable-tool-for-writing-code-in-the-functional-programming-style.aspx
I don't know of any vendor packages off the top of my head, but the XmlSerializer would do that for you pretty easily.

Is there a C# auto formatter that I can use to define custom rules for formatting?

My group has a source analysis tool that enforces certain styles that we have to comply with. I can't change it, and some of the rules are just a pain. One example is that all properties have to come before methods, and all constructors must come before properties. It seems silly to me that I have to take time to do something to the program when to the compiler it is the same. I would like some thing that is a plugin to VS that will let me do things like this automatically. Also, it would be nice to have it automatically put using's inside the namespace block.
You have different possibilities, depending on what exactly you want to do:
Resharper: There is a auto-format function which formats the source code of a single file or all files in the project / solution depending on your selected rules. So you set the settings for braces, naming, whitespaces, operators, lamdas, ... For more information see here. Resharper also supports settings a source- code file for all solutions or a shared settings file which is the same for all persons in the team.
FxCop: I havn't ever used this at work, but it's also a great tool an you can also select the rules which you want to enforce.
Unless they bake it into VS2010, Resharper has the auto formatting capabilities you're probably looking for. CodeSmith probably has it too, I just haven't used it...
There are some formatting options built into VS.
Goto Tools-->Options-->Text Editor-->C#-->Formatting.
They don't include every scenario, but might get you close.
Resharper - what a fantastic tool. I don't think I could manage without it. It must be the ultimate productivity tool for Visual Studio. Re-factoring, code analysis, code formatting, code completion - it has the lot.

Categories

Resources