次の方法で共有


Solution2.Item(Object) Method

Definition

Returns an indexed member of a Projects collection.

public:
 EnvDTE::Project ^ Item(System::Object ^ index);
public:
 EnvDTE::Project ^ Item(Platform::Object ^ index);
EnvDTE::Project Item(winrt::Windows::Foundation::IInspectable const & index);
[System.Runtime.InteropServices.DispId(0)]
public EnvDTE.Project Item (object index);
[<System.Runtime.InteropServices.DispId(0)>]
abstract member Item : obj -> EnvDTE.Project
Public Function Item (index As Object) As Project

Parameters

index
Object

Required. The index of the item to return.

Returns

A Project object.

Implements

Attributes

Examples

Sub SolnItemExample(ByVal dte As DTE2)  
    ' 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 SolnItemExample(DTE2 dte)  
{  
    // 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);  
    }  
}  

Remarks

The value passed to Index is an integer that is an index to an object in its collection. The value of Index can also be a string value that equates to an object in the collection. The exact value that is accepted by Item, though, depends upon the collection and its implementation.

The Item method throws a ArgumentException exception if the collection cannot find the object that corresponds to the index value.

Applies to