Whidbey C# IDE Features

Visual Studio 2005 is going to be released shortly. Whidbey is the codename for this.

Here, I want to share some of my knowledge about new IDE features of C# 2.0

1. Code Expansions: -

A.When we want to include a property for our code, it is very simpler than pervious. Just type 'prop' and hit tab, you will get the property skeleton as shown below.

You can edit the names marked in yellow color.

B.Also, if you want to add a class, it's very simple. Type 'Class' and hit tab, you will get the skeleton as shown below.

You can edit the names marked in yellow colors.

The same way, you can get the code templates for Enum, Struct, switch statement, for loop, foreach loop, if, do-while, else loop.

C.You can also create your own code expansion templates using defined XML schema

2. Refactoring: -

A.Renaming

You can use refactoring to intelligently rename a variable, parameter, method, or a type. Intelligently means that the refactoring tool will distinguish between literal names and words in comments, and different versions of an overloaded method. That is, when renaming a method, you will get the option to change the name of that particular version of the method (in its definition and all its call sites), or all overloaded versions of that method.

If you want to rename you don't have to find and replace everything. Go to the variable, Right Click, choose Refactor and select Rename it gives a windows to enter the new name. After entering a new name, a new window opens that displays the places where the changes will take place. You can view and accept the changes

B.Method ExtractionRefactoring method extraction lets you convert a section of in-line selected code into a method. The extraction removes the original code section, places it into a new private method, and injects a call to the new method in place of the extracted lines.

Before Extracting to method: -

After Extracting to Method: -

When you generate the extracted method signature, the refactoring engine follows the following rules:

1.Any local variable that is defined before the selected code but is used in it becomes an input parameter.

2.Any such local value type variable that is changed by the selected code will be converted to a by-reference parameter (using the ref qualifier).

3.If the selected code does not use any member variables, it will be extracted to a static method.

C.Field Encapsulation: -

This handy refactoring feature allows you to generate a property around a class member. You can use it to encapsulate a public field or to expose a private field as public property. For example, suppose you want to expose the m_Number member variable as a public property:

publicclass MyClass{Int m_Number;}Place the cursor on m_Number and select Encapsulate Field... from the Refactor menu. This will bring up the Encapsulate Field dialog box

Encapsulate Field can recognize a commonly used member variable naming convention and generate the appropriate property name out of it. Meaning, if the member variable is prefixed with m_ or just _, the Encapsulate Field will omit that prefix when suggesting a property name. Of course, you can specify any property name you like.

If you want to make a variable as property, it is very simple. Right Click and select Refactoring and Encapsulate Field. It will add the get and set methods for that particular field.

D.Reorder Parameters

Refactoring allows you to change the signature of a method by adding or removing parameters, and refactoring allows you to change the order of parameters. However, you cannot change the method returned type. You can change the signatures of methods, indexers, and constructors.

For example, suppose you want to change the order of parameters in Add() method in the following Calculator class parameters:

Right-click anywhere inside the method and select Reorder Parameters from the Refactor popup menu. Use the dialog to change the order of parameters by moving parameters up or down

If you want to Remove Parameters of the method, Right Click, select Refactor and Remove Parameters. You will get a small preview window. In the window you can view the changes and apply the changes.

3. Intellisense: -

The last two refactoring features "Surround With and Expansions" are about code typing automation rather than code layout and structure.

a)Surround with generates a template with blank place holders for commonly used statements (such as foreach or exception handling) around a selected code section. For example, to automatically generate a foreach statement around a trace statement, highlight the statement, right-click, and select Intellisense from the pop-up menu, then choose Surround With... and then select For Each

b)If you type "List<products> myList = new" now you will get the datatype automatically although it is a user defined generic datatype...intellisense works fine here.

4. Debugger Visualization: -

The C# IDE has a built-in class designer based on the one in Visio (in terms of functionality). Its look and feel is completely different though.

If you are dealing with the XML file, just go to the xml file types and right click on it. You can view the file data as xml, html or text.

Custom type viewers can be created for debugging purposes that allow you to view, while debugging, a dataset for example. These viewers are extensions to the IDE that can be created by you.