Tips And Tricks: Productivity Tips For The Visual C# 2005 IDE

Here are my notes from this excellent PDC session held in September 2005.

The IDE is very powerful tool, but you do need to learn the tricks. Some features seem to be deliberately hidden!

Keyboard Bindings

I'm using the C# settings.

I think having the ability to customise keyboard settings is completely bonkers. (When using someone else's machine, you've deleted their hard drive when all you meant to do a ^KB ^KK ^KW.)

"Oh! Just click there! Just click there!"

The PDC hosting the presentation expressed the frustration of monitoring user appraisals. Watching users and see them not use the short cuts is so frustrating! He wanted to yell: "Oh! Just click there! Just click there!"

Class Diagrams

Right mouse click on the project, View Class Diagram...

... and you'll have your own class diagram!

Use Class diagrams to explore the framework.

I cannot see how to use solution explorer, but class view seems to work.

For an example, select system.io namespace from the class view.

Right mouse click on the namespace, View Class Diagram...

^WC class view
^WS solution view

Keyboard shortcuts

When wading through source code use:

^MO collapse region
^MM toggle collapse


Use the side buttons on the Explorer Mouse with these last two.

F12 go to Definition

Navigating text. ctrl - and ctrl shift -  to navigate around recent edits.

Use ctrl * to walk back up your "virtual stack" after doing an F12 go to definition command.

Use a ctrl & to walk back again.

Go to a reference - a bit meaningless, as there are bound to be several references. Shift F12 lists all references.

F8 browses throw the list of references. (F8 works for any list window.)

Document management

New menu item: "Close all but this".

as well as "Close all Documents" off Windows Menu

Refactoring

(Explanation to management:  Refactoring makes your code easier to read, maintain and test. No change to outward functionality.)

Code analysis tab on properties window. This is not available in Team Drongo or Team Pleb. (How stupid!)

F2 to rename a file - will prompt to change class name to. Keeps class name and file name in synch.

Extract Method ^R^M

Smart tags

Templatised blocks of code.

editor 'smart tag'.

Code snippets

e.g.  cl ^ space tab tab  will generate class

snippets - xml file. create your own.
C:\Program Files\Microsoft Visual Studio 8\VC#\Snippets\1033\Visual C#

^K^S snippet picker

Generation of method stubs. use ^. when highlight appears.

C:\Program Files\Microsoft Visual Studio 8\VC#\Snippets\1033\Refactoring

when creating your own this function is useful!

<Function>SimpleTypeName(global::System.Exception)</Function>
See MethodStub.snippet
See options, text editor, c#,intellisense.

Debugging

How to stop debug stepping into properties... (You know it's really a field, so don't waste time stepping into the the propertry ever.)

Add an attribute to the accessor
[DebuggerStepThrough()]
Using auto complete the using statement will also be added.

Customise the debugger to change the display. Show the most interesting elements of an array...

Use ToString(). (you may not want that as you are debugging! so...
Use attribute on class:
[DebuggerDisplay("{<field name>}")]

customise
C:\Documents and Settings\Nick\My Documents\Visual Studio 2005\Visualizers\autoexp.cs

never show in debugger:

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
public int D_
{
get { return d_; }
set { d_ = value; }
}

During debug, variable can be examined in the editor window by hovering over the variable.
Hold the control key down to reveal the editor window text.