Поделиться через


Imports Interface

Contains the collection of all project imports for a Visual Basic project. The specified imports statements are passed directly to the compiler and apply to all the files in the project.

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

Syntax

'Declaration
<GuidAttribute("642789F9-210D-4574-96FD-5A653451E216")> _
Public Interface Imports _
    Inherits IEnumerable
[GuidAttribute("642789F9-210D-4574-96FD-5A653451E216")]
public interface Imports : IEnumerable
[GuidAttribute(L"642789F9-210D-4574-96FD-5A653451E216")]
public interface class Imports : IEnumerable
[<GuidAttribute("642789F9-210D-4574-96FD-5A653451E216")>]
type Imports =  
    interface 
        interface IEnumerable 
    end
public interface Imports extends IEnumerable

The Imports type exposes the following members.

Properties

  Name Description
Public property ContainingProject Gets the project that contains the selected item. Read-only.
Public property Count Gets a value indicating the number of objects in the collection. Read-only.
Public property DTE Gets the top-level extensibility object.
Public property Parent Gets the immediate parent object of a given object.

Top

Methods

  Name Description
Public method Add Adds a new import statement to the Imports collection.
Public method GetEnumerator Gets an enumeration for items in a collection.
Public method Item Returns an indexed member of the Imports object. The Item method is the default method for the Imports object.
Public method Remove Removes an imports statement from the Imports collection. The imports statement to be removed may be indexed by either the string specifying the import or by a one-based index.

Top

Remarks

This object specifies the namespaces to import for the project. Elements from imported namespaces may be used in code without fully qualifying the name of the element. For example, if the Imports object contains the Namespace1.Namespace2 import statement, then the two following code statements are equally valid:

Namespace1.Namespace2.SomeMethod()
SomeMethod()

If the imports statement is not in the collection, then the second, unqualified statement above results in a build error.

Examples

' Macro Editor
' This routine displays all the project imports.
Imports VSLangProj
Public Sub ListImports()
   ' The first project is a Visual Basic or C# project.
   Dim vsproject As VSProject = _
      CType(DTE.Solution.Projects.Item(1).Object, VSProject)
        
   Dim projImports As VSLangProj.Imports = vsproject.Imports
   ' For C# projects, projImports will be Nothing.
   If Not (projImports Is Nothing) Then
      Dim i As Integer
      For i = 1 To projImports.Count
         MsgBox(projImports.Item(i))
      Next
   Else
      MsgBox("This project has no imports.")
   End If
End Sub

See Also

Reference

VSLangProj Namespace