Metodo Solution4.FindProjectItem (String)

Trova un elemento in un progetto.

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

Sintassi

'Dichiarazione
Function FindProjectItem ( _
    FileName As String _
) As ProjectItem
ProjectItem FindProjectItem(
    string FileName
)
ProjectItem^ FindProjectItem(
    String^ FileName
)
abstract FindProjectItem : 
        FileName:string -> ProjectItem 
function FindProjectItem(
    FileName : String
) : ProjectItem

Parametri

  • FileName
    Tipo: System.String
    Obbligatorio.Nome dell’elemento del progetto da individuare.

Valore restituito

Tipo: EnvDTE.ProjectItem
Oggetto ProjectItem.

Note

FindProjectItem esegue una ricerca del nome file specificato in base al tipo OpenFile.Il primo progetto individuato che include l'elemento restituisce il proprio oggetto ProjectItem per il nome.Se il file non viene trovato all'interno della soluzione, viene restituito un valore nullriferimento null (Nothing in Visual Basic).

Esempi

Per informazioni sulla modalità di esecuzione di questo codice di componente aggiuntivo, vedere Procedura: compilare ed eseguire gli esempi di codice del modello a oggetti di automazione.

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)
    SolnFindProjectItemExample(_applicationObject)
End Sub

Sub SolnFindProjectItemExample(ByVal dte As DTE2)
    ' This add-in finds a project item in a  solution.
    ' Make sure you have a solution open in Visual 
    ' Studio before running this example.
    Try
        Dim soln As Solution4 =  _
        CType(_applicationObject.Solution, Solution4)
        MsgBox("Finding a project item in the solution ")
        ' Find the specified project.
        Dim proj As ProjectItem
        proj = soln.FindProjectItem _
(soln.Projects.Item(1).ProjectItems.Item(1).Name.ToString())
        MsgBox(proj.Name.ToString())
    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.
    CreateExample((DTE2)_applicationObject);
}

public void CreateExample(DTE2 dte)
{
    // This add-in finds a project item in a solution.
    // Open a solution in Visual Studio before running 
    // this example.
    try
    {
        Solution4 soln = (Solution4)_applicationObject.Solution;
        MessageBox.Show("Finding a project item in the solution.");
        ProjectItem proj;
        proj =
          soln.FindProjectItem
          (soln.Projects.Item(1).ProjectItems.Item(1).Name.ToString());
        MessageBox.Show("The project item found is: " 
          + proj.Name.ToString());
    }
    catch (SystemException ex)
    {
        MessageBox.Show("ERROR: " + ex);
    }
}

Sicurezza di .NET Framework

Vedere anche

Riferimenti

Solution4 Interfaccia

Overload FindProjectItem

Spazio dei nomi EnvDTE100

Altre risorse

Procedura: compilare ed eseguire gli esempi di codice del modello a oggetti di automazione