Auto Suggest With Spell Check And Quick Fix: Visual Studio 2015 Update 2

As we know, Visual Studio supports a lot of IntelliSense and auto suggestions for creating code blocks. But I will show you a much enhanced version of this feature and you will find it very useful.

code

If we write a type name (class/struct/interface…) then Visual studio gives us the suggestion to generate a stub for it. If we are writing a type name for which namespace is not included in using directive in that case it will suggest to include the namespace inside the using directive.

But in new and enhanced feature of auto suggestion you will see an entirely different look.

It will do the following things.

  1. Adding dll reference
  2. Writing namespace in using directive
  3. Correcting the name of type/method/property if it is typed incorrectly

Let’s try to understand all the scenarios one by one.

Write a line of code,

  1. var x = colour.Red;  
code

With Visual Studio 2015 update 2

Now you can see in the screenshot that I have written “colour.Red” whereas it should be “Color.Red”. If I click on the selected option it will automatically correct it and also write the namespace in using directive.

If you are thinking that it will take your time then it’s a myth because you just need to press the shortcut key “ctrl+ dot(.)”

With Visual Studio 2013

To understand that what is new in it I have just written the same code with Visual Studio 2013,

code
If you type anything incorrectly the Visual studio 2013 is not going to provide you any suggestion for that. It will simply say that “The name 'colour' does not exist in the current context”.

If you are thinking that it will work only with in-built Microsoft libraries then it is not the fact. It will work with any other dlls too. Let install Dapper ORM inside the application and then write sMapper instead of SqlMapper.

code

So you can see that I have written sMapper instead of SqlMapper but visual studio is detected it correctly and providing the suggestion to use using statement along with correcting the type name.

Here I want to give you one more tip. If you are not aware of any method and you are not sure that how to use a particular method of that type then Developer Assist extension will help you,

code

To know more about developer Assistant visit here .

The above shown auto suggestion is just a simple example even though it can do a lot. The IntelliSence feature of Visual Studio 2015 update 2 can also add a dll reference along with writing using statement and correcting the type Name.

To understand it in better way do the following thing create a project of class library type inside Visual Studio 2015 update 2 and give the name “AppLogic_SQL” now Add 2 project inside this solution file with name “AppLogic” & “SQLDataAccess”. In project SQLDataAccess write a class DataAccess.cs and inside this write the following codes,
  1. namespace SQLDataAccess  
  2. {  
  3.     public class DataAccess  
  4.     {  
  5.         public static void UpdateAllUsers()  
  6.         {  
  7.             //do something.  
  8.         }  
  9.     }  
Now go to the project “AppLogic” and write below code,
  1. namespace AppLogic  
  2. {  
  3.     public class Logic  
  4.     {  
  5.         DataAcess.UpdateAllUsers  
  6.     }  
  7. }  
Now press Ctrl +. For potential quick fix for more details refer the below image.

code

In the above screenshot you can notice that 3 tasks are being done, 
  1. Adding the namespace in using directive.
  2. Correcting the type (class) and method name.
  3. Adding reference of the DLL inside the current project.

After clicking on the suggestion (potential fix) you will see all the 3 changes in your project for details refer the below screen shot.

refrences

You can explore it for more auto suggestions and auto correction of types, methods, properties, variables etc.

Read more articles on Visual Studio 2015, 2016 & C# 7,

Up Next
    Ebook Download
    View all
    Learn
    View all