Partilhar via


Propriedade Reference3.Identity

Obtém o identificador exclusivo da referência.

Namespace:  VSLangProj80
Assembly:  VSLangProj80 (em VSLangProj80.dll)

Sintaxe

'Declaração
ReadOnly Property Identity As String
string Identity { get; }
property String^ Identity {
    String^ get ();
}
abstract Identity : string with get
function get Identity () : String

Valor de propriedade

Tipo: String
A cadeia de caracteres retornado depende do tipo de referência.

Tipo de referência

Valor retornado

Assembly

Nome do assembly (nome do assembly sem caminho ou extensão)

COM

O formato é:

"GUID\major.minor\localeid\wrappertool"

Por exemplo,

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

é retornado para os objetos de dados 2,5 ActiveX.

Nativo

Identidade do assembly do assembly que está sendo referenciado.

Comentários

Todos os componentes têm um identificador exclusivo. A propriedade de Identity obtém essas informações. Esta propriedade é exclusivo para cada referência, porque uma exceção é gerada se você tentar adicionar uma referência à mesma identidade que uma referência que já está na coleção. Esta propriedade é adequada para indexar a coleção de Reference3 usando o método de Item .

Exemplos

Este exemplo adiciona um assembly e uma referência de COM a Visual Basic ou a um projeto de Visual C# aberto e exibe a propriedade de Identity para cada um. Para executar este exemplo como um suplemento, consulte Como compilar e executar os exemplos de código do modelo de objeto Automation.

Os caminhos padrão para referência adicionada são: <installation root>\ arquivos de programas \ Microsoft.NET \ assemblies primários de Interoperabilidade para o adodb.dll e, <installation root>\ arquivos de programas \ arquivos comuns \ Microsoft \ SpeechEngines para spcommon.dll. Substituir <file path> no exemplo com o ou outros esses caminhos de arquivos apropriados.

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);
}

Segurança do .NET Framework

Consulte também

Referência

Reference3 Interface

Namespace VSLangProj80