VSProjectItem Interface

Contains the information specific to a Visual Basic or C# project item. It is returned by the Object of the ProjectItem object when the project is a Visual Basic or C# project.

Namespace:  VSLangProj
Assembly:  VSLangProj (in VSLangProj.dll)

Syntax

'Declaration
<GuidAttribute("89FF44C6-979D-49B6-AF56-EC9509001DE4")> _
Public Interface VSProjectItem
[GuidAttribute("89FF44C6-979D-49B6-AF56-EC9509001DE4")]
public interface VSProjectItem
[GuidAttribute(L"89FF44C6-979D-49B6-AF56-EC9509001DE4")]
public interface class VSProjectItem
[<GuidAttribute("89FF44C6-979D-49B6-AF56-EC9509001DE4")>]
type VSProjectItem =  interface end
public interface VSProjectItem

The VSProjectItem type exposes the following members.

Properties

  Name Description
Public property ContainingProject Gets the project that the selected item is a part of. Read-only.
Public property DTE Returns the top-level extensibility object.
Public property ProjectItem Gets the ProjectItem object associated with the given object.

Top

Methods

  Name Description
Public method RunCustomTool Runs the custom tool associated with a ProjectItem object. A custom tool is a registered component that implements the IVsSingleFileGenerator interface. Custom tools are similar to designers and editors.

Top

Remarks

The ProjectItems collection of a project contains the ProjectItem objects in the project. The Object property of the ProjectItem object returns an Object reference. The actual type of that reference depends on the project language. In the case of Visual Basic and C#, that object is a VSProjectItem object. To use the VSProjectItem class members, the Object property reference must be explicitly converted to VSProjectItem. The example below demonstrates this conversion using the Visual Basic CType function. The PrjKind enumeration is used to test for the project's type before the conversion.

Examples

Whether a project item has been saved can be determined from the ProjectItem object. This example uses the ProjectItem of the VSProjectItem object to report whether an item has been saved since it was last changed.

' Macro Editor
' Reports whether the specified project item has been saved since the 
' last change.
Imports VSLangProj
Sub IsItemSaved(ByVal aVSProjectItem As VSProjectItem)
   If (aVSProjectItem.ProjectItem.Saved()) Then
      MsgBox(aVSProjectItem.ProjectItem.Name & " is saved.")
   Else
      MsgBox(aVSProjectItem.ProjectItem.Name & " is not saved.")
   End If
End Sub
    
Sub Test()
   Dim pi As VSProjectItem
   pi = CType(Dte.Solution.Projects.Item(1).ProjectItems.Item(1).Object, _
      VSProjectItem)
   IsItemSaved(pi)
End Sub

See Also

Reference

VSLangProj Namespace