Imports EnvDTE Imports System.Collections Imports System.Diagnostics Imports Microsoft.VisualBasic Imports Microsoft.VisualBasic.ControlChars Public Module Module1 Public Const DATATABLE_COLUMN_COLLECTION_KEY As String = ".columnCollection.list" Public Const DATAVIEW_COLUMN_COLLECTION_KEY As String = ".Table" + DATATABLE_COLUMN_COLLECTION_KEY Sub DumpTextToDebugPane(ByVal text As String) Dim outputWin As OutputWindow outputWin = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput).Object Dim ie As System.Collections.IEnumerator = outputWin.OutputWindowPanes.GetEnumerator() While ie.MoveNext() If CType(ie.Current, OutputWindowPane).Name = "Debug" Then Dim debugPane As OutputWindowPane debugPane = CType(ie.Current, OutputWindowPane) debugPane.OutputString(text) Exit While End If End While End Sub Sub DumpDataColumns() Dim win As Window Dim StartLine, EndLine As Integer Dim table As System.Data.DataTable Dim i As Integer = 1 win = ActiveWindow() If win.Type <> EnvDTE.vsWindowType.vsWindowTypeDocument Then MsgBox("This macro can only be run when a text editor window is active.") Else Dim text As String = ActiveDocument().Selection.text() Dim ExpObj As Expression ExpObj = DTE.Debugger.GetExpression(text) Dim columnsExp As Expression Dim obj As Expression Dim rowExp As Expression If ExpObj.IsValidValue Then If (ExpObj.Type <> "System.Data.DataTable") And (ExpObj.Type <> "System.Data.DataView") Then MsgBox("Please make sure a valid DataTable or DataView is selected.") Return End If Else MsgBox("Please make sure a valid DataTable or DataView is selected.") Return End If If ExpObj.Type = "System.Data.DataTable" Then columnsExp = DTE.Debugger.GetExpression(text & DATATABLE_COLUMN_COLLECTION_KEY) ElseIf ExpObj.Type = "System.Data.DataView" Then columnsExp = DTE.Debugger.GetExpression(text & DATAVIEW_COLUMN_COLLECTION_KEY) End If If columnsExp.IsValidValue Then Dim output As String output = GetColumns(columnsExp) DumpTextToDebugPane(vbNewLine & "Column Names for table: " + text + vbNewLine & output) End If End If End Sub Public Function GetColumns(ByVal exp As Expression) As String Dim text As String Dim column As Expression Dim i As Integer Dim name As String For i = 1 To exp.DataMembers.Count If i > 1 Then text &= (vbTab & exp.DataMembers.Item(i).DataMembers.Item(2).Value) Else text &= exp.DataMembers.Item(i).DataMembers.Item(2).Value End If Next Return text End Function End Module