Sdílet prostřednictvím


IVCCollection – rozhraní

IVCCollection Objekt obsahuje funkce, které lze uplatnit u objektu kolekce.

Obor názvů:  Microsoft.VisualStudio.VCProjectEngine
Sestavení:  Microsoft.VisualStudio.VCProjectEngine (v Microsoft.VisualStudio.VCProjectEngine.dll)

Syntaxe

'Deklarace
<GuidAttribute("BA03D89E-872B-4E4F-A186-61BA51119AC0")> _
Public Interface IVCCollection _
    Inherits IEnumerable
[GuidAttribute("BA03D89E-872B-4E4F-A186-61BA51119AC0")]
public interface IVCCollection : IEnumerable
[GuidAttribute(L"BA03D89E-872B-4E4F-A186-61BA51119AC0")]
public interface class IVCCollection : IEnumerable
[<GuidAttribute("BA03D89E-872B-4E4F-A186-61BA51119AC0")>]
type IVCCollection =  
    interface 
        interface IEnumerable 
    end
public interface IVCCollection extends IEnumerable

Typ IVCCollection zveřejňuje následující členy.

Vlastnosti

  Název Popis
Veřejná vlastnost Count Získá hodnotu určující počet objektů v kolekci.
Veřejná vlastnost VCProjectEngine Získá ukazatel objekt modulu projektu.

Nahoru

Metody

  Název Popis
Veřejná metoda GetEnumerator Vrací enumerátor pro položky v kolekci.
Veřejná metoda Item Vybere položku v kolekci.

Nahoru

Poznámky

Například Files vlastnosti VCFilter objekt je kolekce souborů ve složce.

Příklady

Následující příklad ukazuje, jak použít EnablePREfast a AdditionalOptions vlastnosti a nastavte /analyze:WX- přepnout. (Obě vlastnosti nutné provést.) Určení /analyze:WX- znamená, že kód analýzy upozornění považovány za chyby při kompilaci s /WX.Další informace naleznete v tématu /analyze (Analýza kódu).

Chcete-li spustit tento příklad, zadejte a spustit tento příklad, jak je uvedeno v Postupy: Kompilace a spuštění příkladů kódu objektu automatizace.Potom v nové instanci aplikace Visual Studio, načíst Visual C++ projektu a aktivovat doplněk pomocí Správce doplňků.

' 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);
    }
}

Viz také

Referenční dokumentace

Microsoft.VisualStudio.VCProjectEngine – obor názvů

Další zdroje

Výsledky HRESULT vracené modelem projektu

Model objektů rozšíření Visual C++