DTE Properties コレクション
更新 : 2007 年 11 月
環境レベルのプロパティは、[オプション] ダイアログ ボックスに表示される階層に対応するカテゴリに分類されます。[オプション] ダイアログ ボックスを表示するには、[ツール] メニューの [オプション] をクリックします。説明を簡単にするために、このトピックでは、このダイアログ ボックスを [ツール オプション] ダイアログ ボックスと呼びます。たとえば、DTE.Properties("TextEditor", "Basic") は、[ツール オプション] ダイアログ ボックスにある [テキスト エディタ] ノード内の [Basic] ノードの設定を表します。また、ダイアログ ボックス内の設定は、プロパティによって何度も表されます。たとえば、[オプション] ダイアログ ボックスで、[テキスト エディタ]、[Basic]、および [タブ] を順に展開すると、設定の 1 つに [タブ サイズ] があります。これは、TabSize プロパティおよび TabSize プロパティによって表されます。各プロパティ項目には、1 つ以上の値があり、Value プロパティによって表されます。プロパティを使用してオプションの値を変更する方法については、「オプション設定の制御」を参照してください。
「参照」セクションのトピックでは、Visual Studio に付属している定義済みのカテゴリを示しています。ただし、Visual Studio パッケージでは、独自のカテゴリ (ツール オプション ページ) を追加できるため、ユーザーは独自のカスタム ツール オプション ページを作成できます。
メモ : |
---|
[オプション] ダイアログ ボックスの一部のプロパティ ページでは、オートメーションがサポートされていません。オートメーションをサポートするプロパティ ページは、「オプション ページにあるプロパティ項目名の確認」に示されています。 |
同じ Properties コレクション オブジェクトには、さまざまな場所でアクセスできます。たとえば、フォントと色のプロパティ コレクションには、DTE.Properties("Environment", "FontsAndColors") または DTE.Properties("TextEditor", "FontsAndColors") のどちらでもアクセスできます。
使用例
次の例では、[オプション] ダイアログ ボックスで、[テキスト エディタ]、[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#]、および [書式設定] を順に展開し、オプションを表示できます。この操作を行うには、2 番目の Properties パラメータ値を、DTE.Properties("TextEditor", "Basic - Tabs") や DTE.Properties("Environment", "Help - Online") などの表示または変更するオプションに変更します。使用する値については、このトピックの冒頭で示しています。
ここでは、"CSharp - Formatting" を使用し、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 - Formatting")
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
参照
処理手順
概念
[フォントおよび色] ノード プロパティ ([オプション] ページ)
[テキスト エディタ] ノード プロパティ ([オプション] ページ)