- Posted On 23 June 2014
- In Programming
Before starting the post lets have some intro. When I was working in service based MNC we were following Agile(Atleast at starting of the project :-) ) so when some task gets assigned to us it was always having efforts of 8-9 or max 25 hours but in actual as per task's difficulty our every sprint was in crunch and we need to finish the code at very high speed so while doing so these Visual Studio 2012 things helped me alot to deliver the task on time so thought to share it. Lets start exploring them one by one.
Regions, a very well known and useful feature of Visual Studio which helps every developer to keep code well formatted and well organised with collapse and expand facility. When you are working of some complex and long logic wrapping the important parts of code in Region helps to identify the exact location of code and also later on while bug fixing or in maintaince phase too it helps alot.
Following is the example of region in C# code.
#region File Validation Routine string fileName = string.Empty; //all other code #end region
Surround With (Ctrl K+S)
This is one of favoriate feature of Visual Studio and I use it regularly to wrap may code in Try...Catch or in Region and many more options. To use this feature you need to select the required code and then right click (Ctrl K+S) and Surround with. It provides many options such as try catch,if else,using,region and many more.It automatically generates the required code and wraps the selected code within it. I will recomment to use this as it saves a lot time while coding.
Insert snippet ( Ctrl K +X)
As like Surround with ,Insert Snippet provides facility of generating code automatically but the difference is you don't need select any code as per requirement you can generate a block of code and later you can extend it. If you are developing application with MVC then too this feature can saves your time by providing templates for various common code blocks. For HTML tags too it has templates by which can you can generate a HTML element code.
To Do Comments
This feature too is very useful as while developing some feature in application on some routine or validation you are not sure about its implementation so you skip that part and continue with next or sometimes you do some code for testing purpose which are supposed to be removed before final check in but many times we forget and later on it creates problem. With To Do comments you can manage these kind of problems. You just need to write a single to-do comment and in Task List you can see all the places at which you have written some to do comments. For example, you can read this post in which I have explained a bit more about To Do comments.
You know Immediate Window and you are using it frequently while coding. Right? If not then I will surely recommend to use it as it saves a lot time, specially while bug fixing or working with some thrid party tools. In debugging mode only you can try other alternatives with live output without restating the application. I have seen many developers who keeps stopping and starting web application just to confirm the output of their some little change on code which sometime take lots of time if application size is big so better to test your code in immediate window and plan all the code and then just make final changes and test all the code by restarting application.
To lauch Immediate window shortcut is "Ctrl + Alt + I" or "Ctrl+D, I" and link is available under "Debug>Windows>Immediate"
Generate from Usage
This feature of Visual Studio enables us to write a code for non-available method/code and as per your use of method or code automatic the required code gets generated.
e.g. Suppose while writing code you realize that at particular place method which will validate number must be there so while writing a code you can write it like following.
int num = 9; bool isValid = ValidateNumber(num);
So when you generate a method by Right click >Generate > Method Stub, A new method with name ValidateNumber with one int parameter and return type of boolean gets automatically created, you just need to write a actual code of validation within it.
Ctrl+Shift+U & Ctrl+U
These are some shortcuts which I use very frequently to change the case of selected text.
Ctrl + Shift + U makes selected text to capital case.
Ctrl + U makes selected text to small case.
Ctrl K+ D and Ctrl E + F
These too are shortcuts which are useful to format and auto align the code.
Ctrl+K+D : Auto Aligned the all code of document
Ctrl + E +F :If you want to auto align some selected code specially when you don't want much changes to be seen if you compare it with older or latest version your source code repository (eg. TFS) then you can use this shortcut. You just need to select the code and then Ctrl + E+F.
If you are writing very complex code which involves code seperated in different classes or places then bookmarking the current place of code or any other important place of code for easy navigation between them you can bookmark by using shortcut (Ctrl +B, T) same shortcut gets used for toggling.
Once you have bookmarked multiple places then to navigate you can use shortcuts (Ctrl + B, P) for navigating to previous bookmark and (Ctrl + B, N) for jumping to the next bookmark place. To clear all bookmarks you can use shortcut (Ctrl + B, C).
Word Wrap Option
When text extends beyond the visible code pane, you can set this option ON to automatically wrap to the next line. So if you not prefer scrolling horizontly in Visual Studio Code pane then you can enable this option in Tools > Option > Text Editor > C# > Word Wrap or if you want to enable it for all languages then Tools > Option > Text Editor > All Languages > Word Wrap.
Hope you will benefited by using above mentioned Visual Studio features. Do let me know if any other feature is available which is useful while coding. Thanks.
Typewriter - Automatic TypeScript Template generation from C# classes in Visual Studio
Typewriter, an extension for visual studio that generates TypeScript files from C# code files using TypeScript templates. Convert your C# model classes to TypeScript automatically.
Swagger - Powerful Opensource Framework for RESTful API
With a Swagger-enabled API, you get interactive documentation, client SDK generation and discoverability. Swagger Editor allows you to generate code, documentation with ease.
Assembla - Free and private repository to manage your source code online with SVN subversion hosting
With Assembla you can share source code with others online. Free & Private source code repository with SVN Subversion, Git & Perforce Hosting.
Copy changed data in table from one database to another in SQL stored procedure
How to copy or merge changed data in table from one database to another having same schema is the topic of this post.
How to call click or any event only once in jQuery
Know how to execute an click event or any event only once for any element in jQuery. Perform action only once and even not required to unbind event.