IVCCollection.Item 方法
集合中選取某個項目。
命名空間: Microsoft.VisualStudio.VCProjectEngine
組件: Microsoft.VisualStudio.VCProjectEngine (在 Microsoft.VisualStudio.VCProjectEngine.dll 中)
語法
'宣告
Function Item ( _
Index As Object _
) As Object
Object Item(
Object Index
)
Object^ Item(
Object^ Index
)
abstract Item :
Index:Object -> Object
function Item(
Index : Object
) : Object
參數
- Index
型別:System.Object
物件,表示集合中項目的索引。
傳回值
型別:System.Object
集合中的項目。
備註
您可以提供任一個一個以 1 起始的數字索引至集合中的項目,或者提供引號括住的字串,表示集合中項目的名稱。
範例
下列範例會示範如何使用EnablePREfast和AdditionalOptions屬性來設定/analyze:WX-切換。 (若要這麼做被必要這兩個屬性)。 指定/analyze:WX-程式碼分析警告的方法不會被視為錯誤以編譯時/WX。 如需詳細資訊,請參閱 /analyze (程式碼分析)。
若要執行這個範例後,再輸入執行這個範例中所述HOW TO:編譯和執行 Automation 物件模型程式碼範例。 然後,在新的執行個體的Visual Studio,載入Visual C++專案,並使用 [增益集管理員] 啟動增益集。
' Add reference to Microsoft.VisualStudio.VCProjectEngine.
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports System.Diagnostics
Imports Microsoft.VisualStudio.VCProjectEngine
Imports System.Text
Sub EnablePREfastExample(ByVal dte As DTE2)
Dim prj As VCProject
Dim cfgs, tools As IVCCollection
Dim cfg As VCConfiguration
Dim tool As VCCLCompilerTool
Dim sb As New StringBuilder
prj = CType(dte.Solution.Projects.Item(1).Object, _
Microsoft.VisualStudio.VCProjectEngine.VCProject)
cfgs = CType(prj.Configurations, _
Microsoft.VisualStudio.VCProjectEngine.IVCCollection)
cfg = CType(cfgs.Item(1), _
Microsoft.VisualStudio.VCProjectEngine.VCConfiguration)
tool = CType(cfg.Tools("VCCLCompilerTool"), _
Microsoft.VisualStudio.VCProjectEngine.VCCLCompilerTool)
sb.Length = 0
sb.Append("Current project PREfast setting: " _
& tool.EnablePREfast & Environment.NewLine)
sb.Append("Flag: " & tool.AdditionalOptions)
MsgBox(sb.ToString)
' Toggle PREfast setting.
If Not (tool.EnablePREfast = True) Then
' PREfast is not enabled. Turn it and the WX- flag on.
tool.EnablePREfast = True
tool.AdditionalOptions = "/analyze:WX-"
Else
' Toggle the opposite.
tool.EnablePREfast = False
tool.AdditionalOptions = "/analyze:WX"
End If
sb.Length = 0
sb.Append("New project PREfast setting: " _
& tool.EnablePREfast & Environment.NewLine)
sb.Append("Flag: " & tool.AdditionalOptions)
MsgBox(sb.ToString)
End Sub
// Add references to Microsoft.VisualStudio.VCProjectEngine and
// System.Windows.Forms.
using System;
using Extensibility;
using EnvDTE;
using EnvDTE80;
using Microsoft.VisualStudio.VCProjectEngine;
using System.Text;
using System.Windows.Forms;
public void EnablePREfastExample(DTE2 dte)
{
try
{
VCProject prj;
IVCCollection cfgs, tools;
VCConfiguration cfg;
VCCLCompilerTool tool;
StringBuilder sb = new StringBuilder();
prj = (Microsoft.VisualStudio.VCProjectEngine.VCProject)
dte.Solution.Projects.Item(1).Object;
cfgs =
(Microsoft.VisualStudio.VCProjectEngine.IVCCollection)
prj.Configurations;
cfg =
(Microsoft.VisualStudio.VCProjectEngine.VCConfiguration)
cfgs.Item(1);
tools =
(Microsoft.VisualStudio.VCProjectEngine.IVCCollection)
cfg.Tools;
tool =
(Microsoft.VisualStudio.VCProjectEngine.VCCLCompilerTool)
tools.Item("VCCLCompilerTool");
sb.Length = 0;
sb.Append("Current project PREfast setting: " +
tool.EnablePREfast + Environment.NewLine);
sb.Append("Flag: " + tool.AdditionalOptions);
MessageBox.Show(sb.ToString());
// Toggle PREfast setting.
if (!(tool.EnablePREfast == true))
{
// PREfast is not enabled. Turn it and the WX- flag on.
tool.EnablePREfast = true;
tool.AdditionalOptions = "/analyze:WX-";
}
else
{
// Toggle the opposite.
tool.EnablePREfast = false;
tool.AdditionalOptions = "/analyze:WX";
}
sb.Length = 0;
sb.Append("New project PREfast setting: " +
tool.EnablePREfast + Environment.NewLine);
sb.Append("Flag: " + tool.AdditionalOptions);
MessageBox.Show(sb.ToString());
}
catch (System.Exception errmsg)
{
MessageBox.Show("ERROR! " + errmsg.Message);
}
}
.NET Framework 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。