Showing posts with label IDE. Show all posts
Showing posts with label IDE. Show all posts

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

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

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