Reference.DTE 屬性
取得最上層擴充性物件。
命名空間: VSLangProj
組件: VSLangProj (在 vslangproj.dll 中)
語法
'宣告
'用途
屬性值
傳回 DTE 物件。
備註
在 Visual Studio 中,DTE 是其他物件模型經常稱為「應用程式」的 Automation 模型的根物件。
範例
Sub DTEExample(ByVal dte As DTE2)
Dim msg As String = _
"The current Output Window object belongs to the "
Dim output As OutputWindow = dte.ToolWindows.OutputWindow
If IsMacrosIDE(output.DTE) Then
MsgBox(msg & "macros IDE.")
Else
MsgBox(msg & "main IDE.")
End If
output = CType(dte.MacrosIDE, DTE2).ToolWindows.OutputWindow
If IsMacrosIDE(output.DTE) Then
MsgBox(msg & "macros IDE.")
Else
MsgBox(msg & "main IDE.")
End If
End Sub
Function IsMacrosIDE(ByVal ide As DTE) As Boolean
Dim val As Boolean = True
Try
' The MacrosIDE property throws an exception if ide
' is not the main DTE object.
If IsNothing(ide.MacrosIDE) = False Then
val = False
End If
Catch ex As Exception
End Try
Return val
End Function
public void DTEExample(DTE2 dte)
{
string msg = "The current Output Window object belongs to the ";
OutputWindow output = dte.ToolWindows.OutputWindow;
if (IsMacrosIDE(output.DTE))
MessageBox.Show(msg + "macros IDE.");
else
MessageBox.Show(msg + "main IDE.");
output = ((DTE2)dte.MacrosIDE).ToolWindows.OutputWindow;
if (IsMacrosIDE(output.DTE))
MessageBox.Show(msg + "macros IDE.");
else
MessageBox.Show(msg + "main IDE.");
}
bool IsMacrosIDE(DTE ide)
{
bool val = true;
try
{
// The MacrosIDE property throws an exception if ide
// is not the main DTE object.
if (ide.MacrosIDE != null)
val = false;
}
catch (Exception ex)
{
}
return val;
}
請參閱
工作
HOW TO:編譯和執行 Automation 物件模型程式碼範例