Adding Intellisense to Your Custom Code

How To:  Adding Intellisense to your custom code

Applies To:  Visual Studio 2005 and later

Intellisense is one of the biggest productivity enhancements in modern development environments.  Gone are the days of endlessly flipping through 1,000-page developer references just to find a method signature.  Even better, intellisense has the ability to not only show the signature, but also add descriptive information to the method and individual parameters.  This functionality isn't just confined to built-in framework components however.  By using a simple shortcut and specially constructed comments, you can make your own custom code fully self-documenting.  Make a habit of doing so and your fellow developers will thank you over and over again.

Lets take a look at how to do it.  We are going to use C# as our example, but this works almost exactly the same way in VB.NET.

Here is our example method, which takes a DateTime and converts it to a string (yes, I know there is a built in way to do this...  this is just for the sake of providing an example).

        public static String DateToString(DateTime inputDate)
        {
            return inputDate.ToLongDateString();
        }

Pretty straight-forward right?  But lets imagine for a moment that this is a very complex method that takes several parameters and executes hundreds of lines of code.  Making it self-documenting becomes very helpful.  So how do we do it?

Visual Studio has a shortcut to create the proper comment format for you.  Insert a blank line directly above your method declaration, and on that line enter three forward slashes (/// or ''' in VB.NET).  You'll see that Visual Studio creates an XML comment block for you to fill in like so:

        /// <summary>
        /// 
        /// </summary>
        /// <param name="inputDate"></param>
        /// <returns></returns>
        public static String DateToString(DateTime inputDate)
        {
            return inputDate.ToLongDateString();
        }

Now you just fill in the blanks.

        /// <summary>
        /// Takes a DateTime and converts it into a string
        /// </summary>
        /// <param name="inputDate">DateTime you wish to convert to a string</param>
        /// <returns>String representation of the supplied DateTime</returns>
        public static String DateToString(DateTime inputDate)
        {
            return inputDate.ToLongDateString();
        }

The next time you call your method from another piece of code, you find that Visual Studio displays the summary for you, and each parameter is also tagged with your comments.

This also works for entire classes.

Article ID: 6, Created On: 4/9/2012, Modified: 4/9/2012