IVCCollection, interface

Un objet IVCCollection contient les fonctionnalités qui peuvent s'appliquer à un objet de collections.

Espace de noms :  Microsoft.VisualStudio.VCProjectEngine
Assembly :  Microsoft.VisualStudio.VCProjectEngine (dans Microsoft.VisualStudio.VCProjectEngine.dll)

Syntaxe

'Déclaration
<GuidAttribute("F34846C1-D08D-4359-907E-0EE22987618B")> _
Public Interface IVCCollection _
    Inherits IEnumerable
[GuidAttribute("F34846C1-D08D-4359-907E-0EE22987618B")]
public interface IVCCollection : IEnumerable
[GuidAttribute(L"F34846C1-D08D-4359-907E-0EE22987618B")]
public interface class IVCCollection : IEnumerable
[<GuidAttribute("F34846C1-D08D-4359-907E-0EE22987618B")>]
type IVCCollection =  
    interface
        interface IEnumerable
    end
public interface IVCCollection extends IEnumerable

Le type IVCCollection expose les membres suivants.

Propriétés

  Nom Description
Propriété publique Count Obtient une valeur qui indique le nombre d'objets de la collection.
Propriété publique VCProjectEngine Obtient un pointeur d'objet au moteur de projet.

Début

Méthodes

  Nom Description
Méthode publique GetEnumerator Retourne un énumérateur pour les éléments de la collection.
Méthode publique Item Sélectionne un élément dans la collection.

Début

Notes

Par exemple, la propriété d'Files d'un objet d'VCFilter est une collection des fichiers dans un dossier.

Exemples

L'exemple suivant montre comment utiliser les propriétés d'EnablePREfast et d'AdditionalOptions pour définir le commutateur d'/analyze:WX-.(Les deux propriétés sont requises pour cela.) Spécifier /analyze:WX- signifie que des avertissements d'analyse du code ne seront pas traités comme des erreurs lorsque compilant avec /WX.Pour plus d'informations, consultez /analyze (analyse de code).

Pour exécuter cet exemple, entrez et exécutez cet exemple comme décrit dans Comment : compiler et exécuter les exemples de code du modèle objet Automation.Ensuite, dans la nouvelle instance de Visual Studio, chargez un projet de Visual C++ et utilisez le gestionnaire de compléments pour activer la macro complémentaire.

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

Voir aussi

Référence

Microsoft.VisualStudio.VCProjectEngine, espace de noms

Autres ressources

HRESULT retournés par le modèle de projet

Modèle objet d'extensibilité Visual C++