Prime Programming Proficiency, Part 3: Lines-of-code Counter
Implementing the Output Window
The last piece is the Output class. The extensibility object model has an OutputWindowPane. Again, I wrapped the existing OutputWinowPane to add some convenience methods for my specific purposes. Listing 9 shows the code.
Listing 9: A Wrapper for the OutputWindowPane.
Imports EnvDTE Imports System.Diagnostics Public Class Output Private Shared FOutputWindow As OutputWindowPane Shared Sub New() FOutputWindow = GetOutputWindowPane("Project Utility") End Sub Public Shared ReadOnly Property Output() As OutputWindowPane Get Return FOutputWindow End Get End Property Public Shared Sub Clear() FOutputWindow.Clear() End Sub Public Shared Sub Write(ByVal Text As String) FOutputWindow.OutputString(Text) End Sub Public Shared Sub WriteLine(ByVal Text As String) FOutputWindow.OutputString(Text & vbCrLf) End Sub Shared Function GetOutputWindowPane(ByVal Name As String, _ Optional ByVal show As Boolean = True) As OutputWindowPane Dim win As Window = _ DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput) If show Then win.Visible = True Dim ow As OutputWindow = win.Object Dim owpane As OutputWindowPane Try owpane = ow.OutputWindowPanes.Item(Name) Catch e As System.Exception owpane = ow.OutputWindowPanes.Add(Name) End Try owpane.Activate() Return owpane End Function End Class
Build Your Skills Base
Programming requires a huge amount of knowledge. We learn about object models, grammars, libraries and third-party tools, patterns, refactoring, algorithms, threading, database design, testing tools, delegates, events, XML, stylesheets, source control tools, and much more. It is easy to forget how much the average programmer has to know to create even a "Hello World" application.
I hope this three-part series helps you see how many of these skills are tied together to create a whole. Still, all of these skills may only make one a competent programmer. The kind of talent that creates a thing of beauty and artistry is rare indeed and very difficult to attain.
(Eventually, I will get the source for this example posted on my Web site at http://www.softconcepts.com.)
Paul Kimmel is the VB Today columnist, has written several books on .NET programming, and is a software architect. You may contact him at email@example.com if you need assistance or are interested in joining the Lansing Area .NET Users Group (glugnet.org).
Copyright © 2004 by Paul Kimmel. All Rights Reserved.
Page 6 of 6