Condividi tramite


Proprietà Reference3.Identity

Ottiene l'identificatore univoco del riferimento.

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

Sintassi

'Dichiarazione
ReadOnly Property Identity As String
    Get
string Identity { get; }
property String^ Identity {
    String^ get ();
}
abstract Identity : string
function get Identity () : String

Valore proprietà

Tipo: System.String
La stringa restituita dipende dal tipo di riferimento.

Tipo di riferimento

Valore restituito

Assembly

Nome dell'assembly (senza percorso né estensione)

COM

Il formato è il seguente:

"GUID\major.minor\localeid\wrappertool"

Ad esempio,

"{00000205-0000-0010-8000-00AA006D2EA4}\2.5\409\tlbimp"

viene restituito per ActiveX Data Objects 2.5.

Nativo

Identità dell'assembly di riferimento.

Implementa

Reference2.Identity

Note

Tutti i componenti possiedono un identificatore univoco. La proprietà Identity richiama le informazioni. Questa proprietà è univoca per ogni riferimento, dal momento che viene generata un'eccezione se si tenta di aggiungere un riferimento con la stessa identità di un riferimento già presente nell'insieme. Questa proprietà può essere utilizzata per indicizzare l'insieme Reference3, mediante il metodo Item.

Esempi

Nell'esempio riportato di seguito vengono aggiunti un assembly e un riferimento COM a un progetto aperto di Visual Basic o Visual C# e viene visualizzata la proprietà Identity di ciascuno di essi. Per eseguire questo esempio come componente aggiuntivo, vedere Procedura: compilare ed eseguire gli esempi di codice del modello a oggetti di automazione.

I percorsi predefiniti per il riferimento aggiunto sono: <directory radice di installazione>\Programmi\Microsoft.NET\Primary Interop Assemblies per adodb.dll e <directory radice di installazione>\Programmi\File comuni\SpeechEngines\Microsoft per spcommon.dll. Sostituire <percorso file> dell'esempio con questi percorsi di file o altri percorsi appropriati.

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)
    ShowIdentity (applicationObject)
End Sub
Sub ShowIdentity(ByVal dte As DTE2)
    Dim aProject As Project
    Dim aVSProject As VSProject2
    aProject = applicationObject.Solution.Projects.Item(1)
    aVSProject = _
CType(applicationObject.Solution.Projects.Item(1).Object, VSProject2)
    ' Add an Assembly reference and display its identity.
    Dim newRef As Reference3
    ' Replace the <file path> with an actual file path.
    newRef = aVSProject.References.Add("<file path>\adodb.dll")
    MsgBox("Added an Assembly reference, named: " & newRef.Name)
    MsgBox("The Identity of " & newRef.Name & " is " & newRef.Identity)
    ' Add a COM reference and display its identity.
    ' Replace the <file path> with an actual file path.
    newRef = aVSProject.References.Add("<file path>\spcommon.dll")
    MsgBox("Added a COM reference, named: " & newRef.Name)
    MsgBox("The Identity of " & newRef.Name & " is " & newRef.Identity)
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;
    ShowIdentity(((DTE2)applicationObject));
}
public void ShowIdentity(DTE2 dte)
{
    // The first project is a Visual Basic or C# project.
    VSProject2 vsProject = 
((VSProject2)(applicationObject.Solution.Projects.Item(1).Object));
    Reference3 aRef = null;
    // Add an Assembly reference and display its identity.
    // Replace <file path> with an actual file path.
    aRef = (Reference3)vsProject.References.Add
(@"<file path>\adodb.dll");
    MessageBox.Show("Added an Assembly reference, named: " 
+ aRef.Name);
    MessageBox.Show("The Identity of " + aRef.Name + " is " 
+ aRef.Identity);
    // Add a COM reference and display its identity.
    // Replace <file path> with an actual file path.
    aRef = (Reference3)vsProject.References.Add
(@"<file path>\spcommon.dll");
    MessageBox.Show("Added a COM reference, named: " 
+ aRef.Name);
    MessageBox.Show("The Identity of " + aRef.Name + " is " 
+ aRef.Identity);
}

Sicurezza di .NET Framework

Vedere anche

Riferimenti

Reference3 Interfaccia

Overload Identity

Spazio dei nomi VSLangProj80