Search in Help for developer site.

Showing posts with label Visual Studio. Show all posts
Showing posts with label Visual Studio. Show all posts

Friday, 29 December 2017

Resharper Increase your .Net Productivity

ReSharper: Turbocharge your .NET Development

OverView :


Hi folks.. wassup..hope you doing great..!!!.

Today i have come infront of you  guys to share some information about
useful add-in to visual studio.Yes.. today i am gonna explain you all about
ReSharper tool and its key features and also i will be explaining you
why do i recommend you guys to use it in your daily development routine.

What is ReSharper :

ReSharper is a popular developer productivity extension for Microsoft 
Visual Studio. It automates most of what can be automated in your coding 
routines. It finds compiler errors, runtime errors, redundancies, and code 
smells right as you type, suggesting intelligent corrections for them.

ReSharper helps you explore code by visualizing the structure of files, 
type and style hierarchies, call and value chains, project dependencies. 
It allows you to instantly traverse your entire solution and jump right to 
the exact file and line that you are looking for, decompiling library code 
if necessary.

Why ReSharper :



You can spend less time on routine, repetitive manual work and instead 
focus on the task at hand. A robust set of features for automatic 
error-checking and code correction cuts development time and 
increases your efficiency. You'll find that ReSharper quickly pays back its 
cost in increased developer productivity and improved code quality. 
With ReSharper, .NET developers can truly experience what we mean 
when we say "Develop with pleasure!"


Key Features :

·         Error Highlighting and Quick-Fixes


·         Advanced Coding Assistance


·         Numerous Refactorings 


·         Navigation and Search


·         Unit Testing


·         Code analysis and quick fixes


·         Code generation and templates etc.



Some  Important  Links





https://www.jetbrains.com/resharper/docs/ReSharper_DefaultKeymap_VSscheme.pdf


Download Link


      https://marketplace.visualstudio.com/items?itemName=JetBrains.ReSharper


Thank you guys and feel free to drop  your queries in comment box.

Saturday, 21 October 2017

How to create custom code snippets in visual studio

Custom Code Snippets in Visual Studio.

Today i'm going to share a very useful feature of visual studio. Code snippet is a great inbuilt feature of visual studio and we are already familiar with code snippets. We are using them in our daily programming life.

Some inbuilt code snippets for C#:-
  • Prop:- to create a property
  • Ctor:-  to create a class constructor.
  • foreach:- to create a foreach loop
  • so on....
Do you know we can create our own code snippet like above snippets.

See also : ajax pagination and sorting in asp net mvc webgrid

Create custom code snippets in visual studio

We will create a custom code snippet for ASP.NET MVC action method with try catch block.
And will name it as actionMethod.
When we use this actionMethod snippet, It should insert a code as below.
        public ActionResult ActionMethodName()
        {
            try
            {
                //Do some work
            }
            catch (Exception ex)
            {
                throw;
            }
            return View();
    }

Step 1: Create a new project in visual studio and select asp.net application and name it as CustomCodeSnippets, click ok, then select empty project.
because we just need to create a xml file with .snippet file extenstion.


Step 2: After that add a new xml file and name it as actionMethod.snippet


Note: .snippet extension is mandatory to create a snippet file.

After adding this actionMethod.snippet xml file you will see the file as below.

<?xml version="1.0" encoding="utf-8" ?>

Now right click in recently added file and click on Insert Snippet option.

After that it will show snippet options. In that click on Snippet option.

It will insert a code to create our own code snippets as below.

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippet Format="1.0.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <Header>
    <Title>title</Title>
    <Author>author</Author>
    <Shortcut>shortcut</Shortcut>
    <Description>description</Description>
    <SnippetTypes>
      <SnippetType>SurroundsWith</SnippetType>
      <SnippetType>Expansion</SnippetType>
    </SnippetTypes>
  </Header>
  <Snippet>
    <Declarations>
      <Literal>
        <ID>name</ID>
        <Default>value</Default>
      </Literal>
    </Declarations>
    <Code Language="XML">
      <![CDATA[<test>
      <name>$name$</name>
      $selected$ $end$</test>]]>
    </Code>
  </Snippet>
</CodeSnippet>

So in the above code you can understand it by their tag name. They are self described like Title, Author, Shortcut, Description etc.
 In the Code tag we will insert our code.
So now modify the above code as below.

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippet Format="1.0.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <Header>
    <Title>Action Method Code Snippet</Title>
    <Author>HelpForDeveloper</Author>
    <Shortcut>actionmethod</Shortcut>
    <Description>Inserts a code snippets for ASP.NET MVC Action Method</Description>
    <SnippetTypes>
      <SnippetType>Expansion</SnippetType>
    </SnippetTypes>
  </Header>
  <Snippet>
    <Declarations>
      <Literal>
        <ID>ActionMethodName</ID>
        <Default>ActionMethodName</Default>
      </Literal>
    </Declarations>
    <Code Language="CSharp">
      <![CDATA[
      public ActionResult $ActionMethodName$()
        {
            try
            {
                //Do some work
            }
            catch (Exception ex)
            {
                throw;
            }
            return View();
        }
      ]]>
    </Code>
  </Snippet>
</CodeSnippet>

Here we mentioned "actionMethod" as our shortcut.

Step 3: Importing actionMethod.snippet file to Code Snippet Manager to make it available globally.

Go to Tools->Code Snippet Manager


Click on Import and Locate that file, Once you locate that click Ok.
Then do as below.

Now click on finish and your custom code snippet will be copied at this location. "C:\Users\sushil\Documents\Visual Studio 2015\Code Snippets\Visual C#\My Code Snippets"

Our code snippet is ready to use.
To use that create a new ASP.NET MVC project and in the controller file type our code snippet shortcut as "actionmethod"



Visual Studio Intelligence is giving suggestion for our own code snippet. Now click the tab twice and your ready made action method with try catch block shall be inserted as below.

   public ActionResult ActionMethodName()
        {
            try
            {
                //Do some work
            }
            catch (Exception ex)
            {
                throw;
            }
            return View();
        }

Summary:- 
We have seen how to create our own code snippet and how to use them. You can customize it based on your requirement.

Tips: While developing a web application if you notice that you are writing a particular code block again and again then it the right choice for your new custom code snippet. 

Users also read these articles:

Tool to generate C# Model Class or Data Object of a Database Table

Difficulties facing in jquery Ajax call and handling it to get proper response from server side code(MVC)


Thanks for reading.
If you have any doubt please put your comments in the comment section.