Window2.DTE 属性
获取顶级扩展性对象。
命名空间: EnvDTE80
程序集: EnvDTE80(在 EnvDTE80.dll 中)
语法
声明
ReadOnly Property DTE As DTE
Get
DTE DTE { get; }
property DTE^ DTE {
DTE^ get ();
}
abstract DTE : DTE
function get DTE () : DTE
属性值
类型:EnvDTE.DTE
一个 DTE 对象。
实现
备注
在 Visual Studio 中,DTE 对象是自动化模型的根,其他对象模型通常将自动化模型称为“应用程序”。
示例
此示例使用通过 Window2 对象获取的 DTE 对象,确定**“输出窗口”**是属于宏 IDE 还是属于 Visual Studio IDE。
有关如何作为外接程序运行此示例的更多信息,请参见如何:编译和运行自动化对象模型代码示例。
Imports EnvDTE
Imports EnvDTE80
Public Sub OnConnection(ByVal application As Object, _
ByVal connectMode As ext_ConnectMode, ByVal addInInst As Object, _
ByRef custom As Array) Implements IDTExtensibility2.OnConnection
_applicationObject = CType(application, DTE2)
_addInInstance = CType(addInInst, AddIn)
DTEExample(_applicationObject)
End Sub
Sub DTEExample(ByVal dte As DTE2)
Dim msg As String = _
"The current Output Window object belongs to the "
Dim output As Window2 = _
CType(_applicationObject.Windows.Item _
(Constants.vsWindowKindOutput), Window2)
If IsMacrosIDE(output.DTE) Then
MsgBox(msg & "macros IDE.")
Else
MsgBox(msg & "main IDE.")
End If
output = _
CType(dte.MacrosIDE.Windows.Item(Constants.vsWindowKindOutput), _
Window2)
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 will throw 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
using EnvDTE;
using EnvDTE80;
using System.Windows.Forms;
public void OnConnection(object application,
ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
_applicationObject = (DTE2)application;
_addInInstance = (AddIn)addInInst;
DTEExample(_applicationObject);
}
public void DTEExample(DTE2 dte)
{
String msg = "The current Output Window object belongs to the ";
Window2 output =
(Window2)_applicationObject.Windows.Item(Constants.vsWindowKindOutput);
if (IsMacrosIDE(output.DTE))
MessageBox.Show(msg + "macros IDE.");
else
MessageBox.Show(msg + "main IDE.");
output =
(Window2)_applicationObject.Windows.Item
(Constants.vsWindowKindMacroExplorer);
if (IsMacrosIDE(output.DTE))
MessageBox.Show(msg + "macros IDE.");
else
MessageBox.Show(msg + "main IDE.");
}
public bool IsMacrosIDE(DTE ide)
{
try
{
bool val = true;
if (ide.MacrosIDE == null)
val = false;
}
catch (Exception ex)
{
}
return val;
}
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。