Compartilhar via


Reference3.Collection Property

Definition

Gets a collection of References.

public:
 property VSLangProj::References ^ Collection { VSLangProj::References ^ get(); };
[System.Runtime.InteropServices.DispId(2)]
public VSLangProj.References Collection { [System.Runtime.InteropServices.DispId(2)] get; }
[<System.Runtime.InteropServices.DispId(2)>]
[<get: System.Runtime.InteropServices.DispId(2)>]
member this.Collection : VSLangProj.References
Public ReadOnly Property Collection As References

Property Value

Returns a References collection containing one or more Reference3 objects.

Implements

Attributes

Examples

This example displays a references collection for an open Visual Basic or Visual C# project. To run this example as an add-in, see How to: Compile and Run the Automation Object Model Code Examples.

Imports VSLangProj  
Imports VSLangProj2  
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)  
    DisplayCollections(applicationObject)  
End Sub  
Public Sub DisplayCollections(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 aRef As Reference3  
    Dim refStr As String  
    refStr = ""  
    For Each aRef In vsProject.References  
        refStr += (aRef.Name & " " & aRef.Collection & vbCr)  
    Next  
    MsgBox(refStr)  
End Sub  
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;  
    DisplayCollections(((DTE2)applicationObject));  
}  
public void DisplayCollections( DTE2 dte )   
{  
    // The first project is a Visual Basic or C# project.  
    VSProject2 vsProject = ( ( VSProject2 )  
( applicationObject.Solution.Projects.Item( 1 ).Object ) );   
    Reference aRef = null;   
    string refStr = null;   
    refStr = "";   
    foreach ( VSLangProj80.Reference3 temp in vsProject.References )  
    {  
        aRef = temp;  
        refStr += ( aRef.Name + " " + aRef.Collection + "\n" );   
    }  
    MessageBox.Show ( refStr);   
}  

Applies to