Partager via


Solution3.Item, méthode

Retourne un membre indexé d'une collection Projects.

Espace de noms :  EnvDTE90
Assembly :  EnvDTE90 (dans EnvDTE90.dll)

Syntaxe

'Déclaration
Function Item ( _
    index As Object _
) As Project
Project Item(
    Object index
)
Project^ Item(
    [InAttribute] Object^ index
)
abstract Item : 
        index:Object -> Project
function Item(
    index : Object
) : Project

Paramètres

  • index
    Type : Object

Valeur de retour

Type : Project
Objet Project.

Notes

La valeur passée à Index est un entier qui représente l'index d'un objet de sa collection. La valeur de Index peut également être une valeur de chaîne qui équivaut à un objet dans la collection. La valeur exacte acceptée par Item dépend cependant de la collection et de son implémentation.

La méthode Item lève une exception ArgumentException si la collection ne peut pas trouver l'objet correspondant à la valeur d'index.

Exemples

Pour plus d'informations sur l'exécution de ce code de complément, consultez Comment : compiler et exécuter les exemples de code du modèle objet Automation.

Public Sub OnConnection(ByVal application As Object, _
 ByVal connectMode As ext_ConnectMode, ByVal addInInst As Object, _
 ByRef custom As Array) Implements IDTExtensibility2.OnConnection
    _applicationObject = CType(application, DTE2)
    _addInInstance = CType(addInInst, AddIn)
    SolnItemExample(_applicationObject)
End Sub

Sub SolnItemExample(ByVal dte As DTE2)
    ' This add-in iterates through project items in a  solution.
    ' Make sure you have a solution open in Visual 
    ' Studio before running this example.
    Try
        Dim soln As Solution3 = _
        CType(_applicationObject.Solution, Solution3)
        ' Dim solnName As String = _
         System.IO.Path.GetFileNameWithoutExtension(soln.FullName)
        Dim tempString As String = "The items in the solution are: "  _
        & vbCr
        For i As Integer = 1 To soln.Projects.Count
            tempString = tempString & soln.Item(i).Name.ToString()  _
            & vbCr
        Next
        MsgBox(tempString)
    Catch ex As System.Exception
        MsgBox(ex.ToString)
    End Try
End Sub
using System.Windows.Forms;
public void OnConnection(object application,
 Extensibility.ext_ConnectMode connectMode, object addInInst,
 ref System.Array custom)
{
    _applicationObject = (DTE2)application;
    _addInInstance = (AddIn)addInInst;
    // Pass the applicationObject member variable to the code example.
    SolnItemExample((DTE2)_applicationObject);
}

public void SolnItemExample(DTE2 dte)
{
    // This add-in iterates through the project items in a solution.
    // Open a solution in Visual Studio before running 
    // this example.
    try
    {
        Solution3 soln = (Solution3)_applicationObject.Solution;
        String tempString = "The items in the solution are: " + "\n";
        for (int i = 1; i <= soln.Projects.Count; i++)
        {
            tempString = tempString + soln.Item(i).Name.ToString() 
              + "\n";
        }
        MessageBox.Show(tempString);
    }
    catch (SystemException ex)
    {
        MessageBox.Show("ERROR: " + ex);
    }
}

Sécurité .NET Framework

Voir aussi

Référence

Solution3 Interface

EnvDTE90, espace de noms

Autres ressources

Comment : compiler et exécuter les exemples de code du modèle objet Automation