Search only get or set references for property in VS2010? - c#

I use VS 2010 and C#. When I want to found all references to the methods or properties I press Shift+F12. It's possible to find only get or set references for examined property.
It's possible? Maybe I should install any extension?

The poor man's way is to simply remove/comment-out either the getter or setter and recompile: all the errors will be your references. ;)
EDIT: Instead of deleting it (which could be invalid syntax), change the visibility of the particular get/set to private.

I would suggest you to evalutate the ReSharper product which has extremely powerful features that enhance Visual Studio a lot.
Find Usages is what you are looking for.
If you find the ReSharper to be ok (and you will!) then go ahead and buy a license after evaluation.
Just make sure to try it out at least!

Related

If I turn off ReSharper 5's IntelliSense, what am I missing?

During my trial of ReSharper 5, I noticed its version of IntelliSense falls behind Visual Studio 2010's in three ways that were key to me:
ReSharper doesn't support IntelliSense in the "QuickWatch..." debugger utility.
ReSharper's IntelliSense seems to break down for me in .aspx files between the <%= %> tags.
I couldn't find a way to get a listing of properties within an object initializer block. (VS does this if you hit the space key.)
Thankfully ReSharper lets you use Visual Studio IntelliSense alongside its other great features. Am I missing out on anything great by not using ReSharper's IntelliSense?
Well you're losing quite a bit. Here are some quick facts about ReSharper code completion: http://www.jetbrains.com/resharper/webhelp/Coding_Assistance__Code_Completion.html
Smart Completion (Ctrl+Shift+Space in IntelliJ IDEA keymap) is especially useful because in common scenarios it gives you a narrow selection of symbols that you most likely want to complete, and in some cases acts as a shortcut to code generation features
By the way, Smart Completion is the kind of completion that you should use with object initializers: www.jetbrains.com/resharper/webhelp/Coding_Assistance__Code_Completion__Smart.html#object_initializers
As for completion within the <%= %> pair, this should work fine. Please let us know what exactly went wrong by submitting an issue to youtrack.jetbrains.net/issues/RSRP Thanks!
P.S. I work at JetBrains
A five minute comparison I'd say that ReSharper's gives you a bit of help in the typing.
So if you have a method that's A(int a, int b) and you hit ctrl+space when you select A it will add (), will place you in the middle of the brackets and will show you the information about the method. Other than that you're probably not missing much.
For me that is quite helpful, but if you're having trouble doing ASP.NET and those are known bugs / limitations its always best to pick the best tool for the job.
Personally I turn it off. It is annoying and slows me down. Here is a prime example:
No you're not missing much apart from a test runner that supports NUnit. I've had the same problem and also (rather worryingly), hideous performance. I tend to use the productivity power tools extension and the native refactor stuff instead. Info here:
http://visualstudiogallery.msdn.microsoft.com/en-us/d0d33361-18e2-46c0-8ff2-4adea1e34fef
R# also does stuff which I plainly do not want to do and my code ends up littered with commented resharper hints.
I find the CompleteCodeSmart functionality something I use frequently and save me alot of typing.

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.

Find Non Used Functions?

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.

C# check or force naming conventions

I have inherited a few programs from a previous developer who was a little sloppy with naming variables, methods and classes with different capitalization and sometimes underscores.
Is there a program or a way in visual studio to validate the naming of each variable, method, property, constant, class.... I would be fine with the standard C# conventions.
You could look at Microsoft StyleCop and FXCop
I use ReSharper 4.5 for that, which has this advantage, that it allows you to see non-comforming code as you write it.
You also can use NDepend and CQL to check your conventions in a very granular and flexible way. It's great as part of your build script.
Both tools cost money, both are worth it.
Have a look at StyleCop / CodeStyleEnforcer
They'll highlight the bogies but you'll hvae to fix them yourself
http://code.msdn.microsoft.com/sourceanalysis
http://joel.fjorden.se/static.php?page=CodeStyleEnforcer
What you're looking for is StyleCop.
It reads source code to ensure that certain rules are obeyed.
FxCop is used to read the compiled code and generally is not used for this sort of stylistic checking.
FXCop has that and much more.
FXCop and StyleCop can be used to check for conformance to best practices and standards.
FxCop will do the job (or more up-to-date Code Analysis).
This sounds like a job for:
StyleCop
From the website:
StyleCop analyzes C# source code to enforce a set of style and consistency rules. It can be run from inside of Visual Studio or integrated into an MSBuild project
As the others have said: FxCop and StyleCop. ReSharper 4.5 also has configurable naming conventions. The beauty of this is that it'll highlight misnamed items and give you a popup with a suggested name. I'm not 100% sure, but I think this can also be run during ReSharper's 'Code Cleanup' functionality (if it's not, it'd be great if it could be!)
Of course, once you edit and and correct the names, they'll only be correct at that very point time in time. To ensure they're correct now and forever more, integrate FxCop/StyleCop into your Continuous Integration environment. This'll catch the naughty anti-social developers who flaunt the rules and regulations (what community service you give them is up to you, but it often involves being the doughnut and/or coffee purchaser 'till someone else screws up!)

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