Saturday, March 26, 2011

Visual Studio 2010 Tips and Tricks # 5 : Block Editing, Multi-line Coding

  • 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.

Editor_1

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

Editor_2

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

Editor_3

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

Editor_4

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

Editor_5

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

Editor_6

  • 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.

Editor_7

  • 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.

Editor_8

  • 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.

Editor_9

  • 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..

Deployment is currently disabled

 

  • 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.

Deployment_Enable

Thursday, March 24, 2011

Visual Studio 2010 Tips and Tricks # 4 : Code Snippets

 

  • 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. Ninja
  • 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”

prop_1

 

  • 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.

prop_2

  • 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 Party smile

prop_3

 

  • 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,

prop_5

  • Select “try” and hit tab-tab

prop_4

  • 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,

prop_6

  • Use lot of snippets while you are coding and increase your coding productivity. Nerd smile
  • Become a “Ninja Coder” Ninja
  • Stay tuned for my post about “how to create custom snippets”.

Wednesday, March 23, 2011

Visual Studio 2010 Tips and Tricks # 3 : View Call Hierarchy

 

  • 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 In love

 

Call_hierarchy

Wednesday, March 16, 2011

Visual Studio 2010 Tips and Tricks # 2 : Resolve Namespaces

 

  • With Visual Studio 2010 there is a new feature available called “Resolve”.
  • Using “Resolve”, you can automatically add using statements to a class.
  • Shortcut key to invoke this is => Press Ctrl key and “.” key and automatically the namespace will be added.
  • Shown below in this picture, when we enter “DataSet” and if we press “Ctrl” and “.” keys it automatically shows all the namespaces which have the “Data Set” class.

Resolve_1

 

  • We can move up and down using arrow keys to select the right namespace and then if we click enter, that using statement is automatically added to our using section at the top – “How cool !” Nerd smile

Resolve_2

  • Follow my blog for more tips and tricks like this Angel

Visual Studio 2010 Tips and Tricks # 1 : Navigate To

 

  • With Visual Studio 2010 there is a new feature available called “Navigate To”.
  • Using “Navigate to”, you can search for a file name (or) object name (or) method name in your entire solution.
  • Shortcut key to invoke this is => Press Ctrl key and “,” key to bring up the dialog (like shown below), then start typing your search term and it will auto-fill.

 

Navigate_To

  • In the above picture we can see that it lists filenames that start with “Default” like “Default.aspx” & their entire path location as well as it shows all the classes which have “Default” in their name like example “_default” and also it shows all properties “UseDefaultCredentials”.
  • Also if we click on the search result row, it shows the exact file name and the line number.
  • This is very useful to search in solutions which have lots of projects and files.
  • If you are lazy to type, click on the text and press “Ctrl” and “,” key and it even auto-fills the search text. (like shown below in this image).

 

Navigate_To_1

 

Friday, December 17, 2010

Internal test

This is an internal test




Saturday, March 20, 2010

Microsoft Application Architecture – Demystified….

 

We can learn syntax by reading a book but how does someone learn good practices & solid architecture and design.

The question is answered, there is a very good bible I would say of architecture which Microsoft has released and it is a pdf file that can be download for free (good things in life are always free !!!) from this url given below,

http://www.codeplex.com/AppArchGuide

Download PDF here:

http://www.microsoft.com/downloads/details.aspx?FamilyID=ce40e4e1-9838-4c89-a197-a373b2a60df2&displaylang=en

This book is awesome, it covers most of the jargons, the approaches, the design patterns to use in different layers.

MS_Arch_Guide

This book explains the following,

  • Domain driven design,
  • Layered architecture,
  • Service – Oriented architecture,
  • Rich Client application design,
  • Rich Internet Application (RIA) design,
  • Presentation / Service / Business / Data Layer Guidelines,
  • Talks about REST – Representational State Transfer
  • Talks about workflow, messaging & cloud.

This is really an awesome book, a must read for any developer.

Saturday, February 27, 2010

Autodiagrammer – Visual Studio Class Diagram generation tool

 

For one of my projects I was trying to use the Visual Studio Class diagram to quickly generate class diagram to understand the existing design. The VS IDE kept giving errors on not being able to generate class diagram. So I was searching for a 3rd party Free class diagram generating tool and found “Autodiagrammer”.

Sacha Barber has done an excellent job coding this tool, it uses reflection and hence you can run this on compiled dot net projects and it will generate a beautiful class diagram and even align it for you.

You can download it from Code project here

refelctor_Addin

Ubuntu – Linux for Human Beings !!!

 

I wanted an OS where I can download files from the net without the worries of malware or virus and I came upon “Ubuntu”. They had a very nice caption - “Linux for Human Beings”. 

I have prior experience working in Caldera Open Linux & Red Hat, but somehow I got drifted & now landed on Microsoft world.   I have seen my peers type very fast on terminal shell or on vi editor (especially kicha & deepak) and always wondered how they can keep staring at a black and white console without any graphics for the entire day.  But distributions have changed a lot, no need to mount/unmount devices, it has become like windows (plug & play) and Ubuntu really rocks, it has the similarity to its windows counterparts and at the same time provides the security of a linux distribution.

Definitely give it a try.

Ubuntu-2010-02-25-20-50-42

  1. You can download Ubuntu from here Downbload Ubuntu 9.10
  2. Also there is “Google Chrome” , “Transmission Bit Torrent Client” and lots of applications.
  3. And entire thing runs great even on just 512 MB Ram on my VM.
  4. What more can one ask for !!!!