Microsoft & .NET .NET Incremental Intellisense Improvements in VS2010

Incremental Intellisense Improvements in VS2010

Introduction


Some improvements like LINQ are substantial, and some
just make our lives a little easier. Intellisense in VS2010
has an improvement that is incremental and will make the
life of a programmer a little easier.


In VS2008 Intellisense listed members alphabetically by
matching characters as you type them. In VS2010 Intellisense
lists members using a contains-a approach. Let’s take a few
minutes to explore this incremental improvement to the
VS2010 IDE.


Evolution Lived


In a very early version of C++ I realized one could
modify the basic IO functions like printf and add a second
version of the methods that wrote directly to a second video
buffer. The primary implementation of these methods wrote to
the primary video and comprised the programs output. By
adding a second monitor-a CGA monitor-and adding the
equivalent of trace statement and sending them to the CGA
video memory you can have your primary output, which in
those days was a text-based GUI-display, on your primary
monitor and trace statements appear on the CGA monitor.
Viola! Two monitors in the days before it was en vogue.


Video buffer memory is still accessible. To see this open
a cmd window, run the debug.exe program and send some data
right to video memory. (For the demo I am using EGA video
memory because I can’t recall the CGA video memory
addresses.) It is worth noting that odd numbered memory
addresses at EGA memory represent the background and
foreground RGB colors, and that my typographic errors (shown
in Figure 1) show you just how error prone this approach can
be (which in turn demonstrates why good debugging tools were
and still are so necessary).


RGB Grid
Click here for larger image


raw data right into EGA video memory
Click here for larger image

Figure 1: Entering the raw data right into EGA video memory
will display ASCII characters and RGB colors directly to
video memory.

Thankfully debugging evolved shortly thereafter with
Borland’s Turbo Pascal Integrated Development Environment
(IDE) and continue to evolve today. Now we have built-in
Output windows and Intellisense that make debugging what’s
going on and figuring out what code base we have to work
with substantially easier. (To demonstrate Intellisense for
VS2010 I will demonstrate how to redirect IO using .NET in
the section “The New and Improved Intellisense”.)


Intellisense in Visual Studio 2008


Intellisense in Visual Studio works by displaying members
alphabetically. When you type an object name followed by the
member of an operator (.) and some alpha-numeric characters
Visual Studio will display a drop down window, the first
member that start with those characters and then the members
that follow alphabetically. Visual Studio 2010 improves on
this approach.


The New and Improved Intellisense


When you type an object name, followed by the member of
operator in Visual Studio 2010, Visual Studio will display
all of the members that start with or contain those
characters. Instead of a starts-with, alphabetic listing,
Visual Studio 2010 displays a list of members that contain
those characters anywhere in the member name, as long as
those characters are in the same relative order and the case
matches.


To demonstrate, the code in Listing 1 shows you how to
redirect console IO to a WinForm of your choosing, instead
of the IDE’s Output window. I will use this code to show you
how Intellisense lists members in VS2010. (Listing 2 shows
you how to add a TextBox to a form and initialize the
MyStreamWriter class with the TextBox,
resulting in Console Write and
WriteLine method calls buffering data in the
Form’s TextBox.)


Listing 1: Building your own debug window in VS2010 using
console IO redirection.


Imports System.Windows.Forms
Imports System.Text

Public Class MyStreamWriter
Inherits System.IO.TextWriter

Private control As TextBoxBase
Private Builder As StringBuilder

Public Sub New(ByVal control As TextBox)
Me.control = control
AddHandler control.HandleCreated, _
New EventHandler(AddressOf OnHandleCreated)
End Sub

Public Overrides Sub Write(ByVal ch As Char)
Write(ch.ToString())
End Sub

Public Overrides Sub Write(ByVal s As String)
If (control.IsHandleCreated) Then
AppendText(s)
Else
BufferText(s)
End If
End Sub

Public Overrides Sub WriteLine(ByVal s As String)
Write(s + Environment.NewLine)
End Sub

Private Sub BufferText(ByVal s As String)
If (Builder Is Nothing) Then
Builder = New StringBuilder()
End If
Builder.Append(s)
End Sub

Private Sub AppendText(ByVal s As String)
If (Builder Is Nothing = False) Then
control.AppendText(Builder.ToString())
Builder = Nothing
End If

control.AppendText(s)
End Sub

Private Sub OnHandleCreated(ByVal sender As Object, _
ByVal e As EventArgs)
If (Builder Is Nothing = False) Then
control.AppendText(Builder.ToString())
Builder = Nothing
End If
End Sub

Public Overrides ReadOnly Property Encoding() As System.Text.Encoding
Get
Return Encoding.Default
End Get
End Property
End Class



Listing 2: Initialize MyStreamWriter with a TextBox
residing on a form to send Console IO to the TextBox instead
of a command window or the Output window in Visual
Studio/


Public Class Form2
Private writer As MyStreamWriter = Nothing

Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
writer = New MyStreamWriter(TextBox1)
Console.SetOut(writer)
End Sub

End Class


Look at the Inherits System.IO.TextWriter statement in Listing 1. If you type System.IO. then Intellisense in Visual Studio 2010 will start with an alphabetic listing of members. When you start typing the listing is refined. If you type capital T, as in System.IO.T, instead of an alphabetic listing with members starting with T Intellisense will list all members starting with or containing a capital T. In Visual Studio 2010 a capital T will result in PathTooLongException,TextReader, and TextWriter. The logic here being what’s the point of listing members that have no T just because they precede or follow members with T alphabetically.


Continuing the above scenario if you type System.IO.TW then the TextWriter method will be displayed because TextWriter is the only member with a capital T and W in that order (even though there are letters in between).


Summary


Intellisense has been incrementally improved in Visual Studio 2010. Instead of a associative alphabetic listing only members that contain the actual letters you type are displayed. If a member doesn’t contain one of your letters then the member is filtered out.


The historical perspective on dual monitor debugging and tracing was added because in part this is the kind of thing that floats in my head. However, it may be interesting to newer developers to learn something about the ongoing existence of older solutions and contrast those to how much things have improved. Programmers used to have to memorize everything before Intellisense, and debugging was a painstaking process of manually examining code and write line statements. Integrated debuggers and trace windows are a relatively new invention, spanning a period of less than one person’s career in computer science.


The sample code was added just so you’d have some code to chew on to play with Intellisense. The console redirect technique is a nice tool to keep around and it is fun to play with, but you can use any code to explore the changes to Intellisense. (The console code was originally published as “Redirect I/O to a TextBoxWriter in .NET” in April, 2006.)


About the Author


Paul Kimmel is the VB Today columnist for CodeGuru and has written several books on object-oriented programming and .NET. Check out his upcoming book Professional DevExpress ASP.NET Controls (from Wiley) now available on Amazon.com and fine bookstores everywhere. Look for his upcoming book Teach Yourself the ADO.NET Entity Framework in 24 Hours (from Sams). You may contact him for technology questions at [email protected] .com. Paul Kimmel is a Technical Evangelist for Developer Express, Inc, and you can ask him about Developer Express at [email protected] and read his DX blog at http:// community.devexpress.com/blogs/paulk.

Latest Posts

Related Stories