共用方式為


VSProject2.Imports 屬性

取得與專案關聯的 Imports 物件。對 C# 專案來說,Imports 屬性是設定為 Nothing (nullNull 參照 (即 Visual Basic 中的 Nothing) 參考)。

命名空間:  VSLangProj80
組件:  VSLangProj80 (在 VSLangProj80.dll 中)

語法

'宣告
ReadOnly Property Imports As Imports
Imports Imports { get; }
property Imports^ Imports {
    Imports^ get ();
}
abstract Imports : Imports
function get Imports () : Imports

屬性值

型別:VSLangProj.Imports
Imports 集合,每個項目都代表 Import 陳述式。

備註

C# 專案並不具有專案匯入。對 C# 專案來說,Imports 的值是 Nothing (nullNull 參照 (即 Visual Basic 中的 Nothing) 參考)。

範例

若要將此範例當做增益集來執行,請參閱 HOW TO:編譯和執行 Automation 物件模型程式碼範例。開啟 Visual Basic 專案,再執行此範例。

[Visual Basic]

' Add-in
Imports VSLangProj
Imports VSLangProj80

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)
    ListImports(applicationObject)
End Sub

Sub ListImports(ByVal dte As DTE2)
    ' The first project is a Visual Basic or C# project.
    Dim vsproject As VSProject2 = _
    CType(applicationObject.Solution.Projects.Item(1).Object,_
    VSProject2)

    Dim projImports As VSLangProj.Imports = vsproject.Imports
        ' For C# projects, projImports will be Nothing.
    If Not (projImports Is Nothing) Then
        Dim i As Integer
        Dim str As String
        str = ""
        For i = 1 To projImports.Count
            str = (str & str.Concat(projImports.Item(i)) & vbCrLf)
         Next
        MsgBox(str)
    Else
        MsgBox("This project has no imports.")
    End If
End Sub

[C#]

using System.Windows.Forms;
using VSLangProj;
using VSLangProj2;
using VSLangProj80;
public void OnConnection(object application, ext_ConnectMode
 connectMode, object addInInst, ref Array custom)
{
    applicationObject = (DTE2)application;
    addInInstance = (AddIn)addInInst;
ListImports((DTE2)applicationObject);
}
public void ListImports( DTE2 dte ) 
{ 
// The first project is a Visual Basic or C# project.
    VSProject2 vsproject = ( ( VSProject2 )
(applicationObject.Solution.Projects.Item( 1 ).Object ) ); 
    VSLangProj.Imports projImports = vsproject.Imports; 
    // For C# projects, projImports will be Nothing.
    if ( !(  projImports == null )) 
    { 
        int i = 0; 
        string str = null; 
        string str1 = projImports.Count.ToString();
        MessageBox.Show("The number of Imports is: " + str1); 
        MessageBox.Show( projImports.ContainingProject.Name ); 
        str = ""; 
        for ( i=1; i<=projImports.Count; i++ ) 
        { 
            str = ( str + String.Concat( projImports.Item( i ) )
 + "\n" ); 
        } 
        MessageBox.Show( str); 
    } 
    else 
    { 
        MessageBox.Show( "This project has no imports."); 
    } 
}

.NET Framework 安全性

請參閱

參考

VSProject2 介面

Imports 多載

VSLangProj80 命名空間

Imports