DTE 属性集合
环境级属性被组织到与**“选项”对话框中显示的层次结构相对应的类别中。 例如,DTE.Properties("TextEditor", "Basic") 表示“选项”** 对话框中**“文本编辑器”节点下的“基本”** 节点中的设置。 这些页的许多设置在对话框中也可以用属性表示。 例如,在**“文本编辑器”节点下的“基本”节点的“选项卡”页的设置是“选项卡大小”**。 此设置由 TabSize 和 TabSize 属性表示。 每个属性项用拥有由 Value 属性表示的一个或多个值。 有关如何使用特性更改值的信息,请参见 控制选项设置。
下列文件列出了包含在 Visual Studio 中设置的预定义类.
要将设置添加到现有“选项”页面,或将自定义页面添加到“选项对话框,请使用 Visual Studio SDK。 有关更多信息,请参见Development Tools Ecosystem Partner Portal(开发工具生态系统合作伙伴门户)网站。
备注
“选项”对话框中的某些页不支持自动化。关于属性页支持自动化的信息,请参见 确定“选项”页中属性项的名称。
若要在集成开发环境 (IDE) 中打开**“选项”对话框,请在“工具”菜单上单击“选项”**。
示例
以下示例演示如何查看“选项”对话框中“文本编辑器”节点下的“C#”中的“常规”可访问属性项。 请注意,在节点中,“C#”节点必须表示为“CSharp”。有关如何运行外接程序示例的更多信息,请参见 如何:编译和运行自动化对象模型代码示例。
' Add-in code.
Public Sub OnConnection(ByVal application As Object, ByVal connectMode _
As Extensibility.ext_ConnectMode, ByVal addInInst As Object, ByRef _
custom As System.Array) Implements Extensibility.IDTExtensibility2.OnConnection
applicationObject = CType(application, EnvDTE.DTE)
addInInstance = CType(addInInst, EnvDTE.AddIn)
' Pass the applicationObject member variable to the code example.
PropertiesExample (applicationObject)
End Sub
Sub PropertiesExample(ByVal dte As DTE)
' Create and initialize a variable to represent the C#
' text editor options page.
Dim txtEdCS As EnvDTE.Properties = _
DTE.Properties("TextEditor", "CSharp")
Dim prop As EnvDTE.Property
Dim msg As String
' Loop through each item in the C# text editor options page.
For Each prop In txtEdCS
msg += ("PROP NAME: " & prop.Name & " VALUE: " & _
prop.Value) & vbCr
Next
MsgBox(msg)
End Sub
// Add-in code.
Using System.Windows.Forms;
public void OnConnection(object application,
Extensibility.ext_ConnectMode connectMode, object addInInst,
ref System.Array custom)
{
applicationObject = (_DTE)application;
addInInstance = (AddIn)addInInst;
// Pass the applicationObject member variable to the code example.
PropertiesExample((DTE)applicationObject);
}
public void PropertiesExample( DTE dte )
{
// Create and initialize a variable to represent the C#
// text editor options page.
EnvDTE.Properties txtEdCS =
dte.get_Properties( "TextEditor", "CSharp" );
EnvDTE.Property prop = null;
string msg = null;
// Loop through each item in the C# text editor options page.
foreach ( EnvDTE.Property temp in txtEdCS )
{
prop = temp;
msg += ( "PROP NAME: " + prop.Name + " VALUE: "
+ prop.Value ) + "\n";
}
MessageBox.Show( msg);
}
在下面的示例中,对上一个示例进行了细微的修改,您可查看嵌套节点的设置,在此示例中,**“C#”节点中的“格式设置”节点位于“文本编辑器”**节点下。 要进行更改,请将第二个 Properties 参数的值更改为您要查看或更改的设置,例如 DTE.Properties("TextEditor", "Basic-Specific") 或 DTE.Properties("Environment", "ProjectsAndSolution")。 要使用的值已在本文档的开始部分列出。
本例使用“CSharp - 格式设置”查看 C# 文本编辑器的**“格式”**设置。
' Add-in code.
Sub PropertiesExample()
' Create and initialize a variable to represent the C#
' Formatting text editor options page.
Dim txtEdCSFormat As EnvDTE.Properties = _
DTE.Properties("TextEditor", "CSharp-Specific")
Dim prop As EnvDTE.Property
Dim msg As String
' Loop through each item in the C# Formatting Options page.
For Each prop In txtEdCSFormat
msg += ("PROP NAME: " & prop.Name & " VALUE: " & _
prop.Value) & vbCr
Next
MsgBox(msg)
End Sub