Look at Code Definition Window in Visual Studio 2008

In this article, we will look into code definition window and its features. We can use this window to see the code that defines the selected code object. This window is a read-only editor, which can display the definition of the selected item stored in a file or referenced by the project. This window can be viewed by selecting View menu a Code Definition Window. This window on loading first time, displays the definition of the last item selected. If the definition of the selected item is not present or not accessible, it will show "No definition selected". We can dock this window like other windows of Visual Studio.

This window is available while programming in C++ or C# languages only. It is not available under Visual Basic.

We will look into the features of this window by a sample application in Visual Studio 2008. Create a blank solution and name it as CodeDfnWindowSoln. Now add a Class Library to the solution with name as CodeDefnWindowLib. Now, add below lines of code to the Class1.cs:

public class Class1
    {
        public static string GetDate()
        {
            return DateTime.Now.ToLongDateString();
        }
        public string GetTime()
        {
            return DateTime.Now.ToLongTimeString();
        }
    }

Add a console application named as CodeWindowClient to the solution with below lines of code in it:

namespace CodeWindowClient
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(CodeDefnWindowLib.Class1.GetDate());
            CodeDefnWindowLib.Class1 testCodeWindow = new CodeDefnWindowLib.Class1();
            Console.WriteLine(testCodeWindow.GetTime());
            Console.WriteLine();
        }
    }
}

Add the project reference of CodeDefnWindowLib to the console application, when we select any method of Class1, it will show its definition in Code Definition Window as shown below:

image1.gif

Even though it is a read-only editor, we can still edit it by selecting "Edit Definition". This will open the definition file in the editor and positions the cursor at the selected item's definition for editing.

We can get the definition of an item by positioning the cursor on it in the main editor or selecting it in Object Browser. When we add a reference to the dll instead of a project, than it will display only members of the class as shown below:

image2.gif

Below is the list of details displayed for an item in Code Definition Window based on its type:

Selected item's type Details displayed
Type like class Displays entire file having the class definition
Partial Types Displays first definition file found in the list of definitions
Method Displays file containing the method definition with cursor positioning at the method's definition.

Note: The option for selecting [viewing] Code Definition Window may change based on Visual Studio settings selected.

I am ending the things here. I hope this article will be helpful for all.


Similar Articles