skip to main |
skip to sidebar
- This is one of my favorite tricks in VS 2010 IDE. This one is more cool than my previous post [Visual Studio 2010 Tips and Tricks #4: Code Snippets ]
- Did you know you can select any vertical area of your code by using “ALT” key and your “Mouse” in the Code area inside the editor.
- Say we need to create Model class with lots of string variables and “Get”, “Set”. You can follow the tip#4 and use prop code snippet (or) you can use this Block Editing tip.

- First select a vertical region of your code by pressing the “Alt” key and selecting a vertical line as shown above.

- Start typing “public string” and see it fills in all the lines not just one line (as shown above).

- Now press “Esc” to go out of this mode and start typing your Member names

- Now again vertical select a region by pressing “Alt” key and use your mouse.

- And enter “{ get; set; }” and your properties are done.

- Yes but it looks ugly with lot of spaces in between, so use my previous tip [ Tip to autoformat code ] and select these lines and press “Ctrl + E + Ctrl F” to tidy up the code.

- When there are lot of similar lines this approach is very helpful to code faster.
- Say you want to convert all the properties from “public” to “internal”, this can be done very easily using our “Block” editing trick.
- First use “ALT” key and select all the public word in all the lines.

- Now start typing “internal” and you just renamed multiple lines. You may ask why not use “Quick Replace” but this is very helpful if you only want to apply the changes to only few lines and not the entire document.

- This approach is very useful in situations say to enter comments for all lines, say to prefix “M_” or “_” to convert local variables to global etc..
- So you write a new MS Test Unit test and you try to run the test and you get a “Deployment is currently disabled” error? So how to fix this.
- This happens if your unit test is referring a method which has a deployment Item (say whether it is a test file or a referred dll), in your code you would see [DeploymentItem(pathtofile)] Annotation.
- This is a very simple fix.
- Try to find out which “.testsettings” file is currently in use, by default it is the “Local.testsettings”, double click on it to open the “Test Settings” popup window, in that window click on “Deployment” Item in the left to see the “Deployment” settings screen as shown below.
- Check the checkbox which says "[*] Enable deployment” and try to save the file and try running your test again and it should work.

- This is not a new feature, Code Snippets did exist in previous versions of Visual Studio.
- Let us look at what are code snippets and how to use them.
- Trust me they are very helpful for rapid application development.

- Assume you are creating a class with member variables and basic getter, setter methods. Now you can sit and write the entire line for each member variable (or) you can make it rapid by following the steps shown below,
- If you right click on your project and select “Add –> New Class –> enter class name”, it creates the class stub.
- Now go in to the class and type “prop”

- A drop-down gets shown select “prop” and hit tab twice (tab-tab)
- It will auto-fill the default datatype “int” and puts the “Get/Set” for you.

- Now if you want to change the datatype, click on “tab” and enter say “DateTime” on top of “int”.
- And click another “tab” and type in your property name and that’s it you just wrote one member variable so fast


- Now having enjoyed rapid authoring, you may be wondering is there more auto-fill’s for most common syntax/structures.
- Yes there is, for example, say you want to enter try catch. Just enter try and the dropdown shows available snippets,

- Select “try” and hit tab-tab

- Cool right you just saved yourself time entering the braces and aligning them etc..
- Yes, so your next question is how do I know what all snippets are there, it is very easy,
- Just right click on your code, select “Insert Snippet” or use short cut key “CTRL + K AND CTRL + X” to show the “Insert snippet” option.
- Select the folder, say “Visual C#” and see all available snippet options, as shown below,

- Use lot of snippets while you are coding and increase your coding productivity.

- Become a “Ninja Coder”

- Stay tuned for my post about “how to create custom snippets”.
- One of the features I like the most with VS 2010 that I use daily is the “Call Hierarchy”.
- Say you are in a method and you want to know what all methods “Call In” to your method, then this is the most easiest way to do it.
- Just click on your method and use shortcut key (CTRL + K and CTRL+T) and the call hierarchy window will be shown, or just right-click and select “View Call Hierarchy”.
- You can keep drilling down.
- Another nice feature is the “Call Sites” window which is on the Right hand side of the “Call Hierarchy” window. It shows the entire line where the method is called and also gives the file name and the line number. Double click on the row and it takes you to the file.
- VS 2010 is one of the best IDE’s out there, make full use of it
