Condividi tramite


Metodo Solution2.Item (Object)

Restituisce un membro indicizzato di un oggetto Projects raccolta.

Spazio dei nomi:  EnvDTE80
Assembly:  EnvDTE80 (in EnvDTE80.dll)

Sintassi

'Dichiarazione
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

Parametri

  • index
    Tipo: System.Object
    obbligatorio.Indice dell'elemento da restituire.

Valore restituito

Tipo: EnvDTE.Project
In Project oggetto.

Note

il valore passato a Index è un Integer che è un indice a un oggetto nella raccolta.il valore di Index può anche essere un valore stringa che corrisponde a un oggetto nella raccolta.Il valore esatto che viene accettato da Item, tuttavia, è possibile dipendere dalla raccolta e dall'implementazione.

Item il metodo genera un'eccezione ArgumentException eccezione se la raccolta impossibile trovare l'oggetto che corrisponde al valore di indice.

Esempi

Per informazioni su come eseguire il codice del componente aggiuntivo, vedere Procedura: compilare ed eseguire gli esempi di codice del modello a oggetti di automazione.

Nell'esempio vengono scorsi i progetti in una soluzione aperta.

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 Solution2 = _
        CType(_applicationObject.Solution, Solution2)
        ' 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
//make sure to add this reference to your project references
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
    {
        Solution2 soln = (Solution2)_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);
    }
}

Sicurezza di .NET Framework

Vedere anche

Riferimenti

Solution2 Interfaccia

Overload Item

Spazio dei nomi EnvDTE80