다음을 통해 공유


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
    형식: Object

    컬렉션의 항목 색인을 나타내는 개체입니다.

반환 값

형식: Object
컬렉션의 항목입니다.

설명

1부터 시작 번호 이거나 컬렉션에 있는 항목에 대 한 인덱스를 제공 하거나 컬렉션에 있는 항목의 이름을 나타내는 따옴표 붙은 문자열을 제공할 수 있습니다.

예제

다음 예제에서는 사용 하는 방법은 EnablePREfastAdditionalOptions 속성을 설정 하는 /analyze:WX- 전환. (속성이 모두이 필요 합니다.) 지정 /analyze:WX- 사용 하 여 컴파일할 때 코드 분석 경고는 오류로 처리 되지 것입니다 /WX. 자세한 내용은 /analyze(코드 분석)를 참조하십시오.

이 예제를 실행 하 고 입력에 설명 된 대로이 예제를 실행 하려면 방법: 자동화 개체 모델 코드의 예제 컴파일 및 실행. 다음의 새 인스턴스에서 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 보안

참고 항목

참조

IVCCollection 인터페이스

Microsoft.VisualStudio.VCProjectEngine 네임스페이스