Reference3.Identity 属性

获取引用的唯一标识符。

命名空间:  VSLangProj80
程序集:  VSLangProj80(在 VSLangProj80.dll 中)

语法

声明
ReadOnly Property Identity As String
string Identity { get; }
property String^ Identity {
    String^ get ();
}
abstract Identity : string
function get Identity () : String

属性值

类型:System.String
返回的字符串取决于引用类型。

引用类型

返回的值

程序集

程序集名称(没有路径或扩展名的程序集名称)

COM

格式为:

“GUID\major.minor\localeid\wrappertool”

例如,

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

将被返回(ActiveX Data Objects 2.5)。

Native

引用的程序集的程序集标识。

备注

所有组件都有一个唯一的标识符。 Identity 属性获取该信息。 该属性对于每个引用都是唯一的,所以如果尝试添加的引用与集合中已存在的某个引用具有相同的标识,则将引发异常。 通过使用 Item 方法对 Reference3 集合进行索引时适合使用此属性。

示例

此示例向打开的 Visual Basic 或 Visual C# 项目添加程序集和 COM 引用,并显示每个引用的 Identity 属性。 若要将此示例作为外接程序运行,请参见如何:编译和运行自动化对象模型代码示例

所添加的引用的默认路径为:对于 adodb.dll 为 <安装根目录>\Program Files\Microsoft.NET\Primary Interop Assemblies,对于 spcommon.dll 为 <安装根目录>\Program Files\Common Files\SpeechEngines\Microsoft。 请将示例中的 <file path> 替换为这些文件路径或其他适当的文件路径。

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

.NET Framework 安全性

请参见

参考

Reference3 接口

Identity 重载

VSLangProj80 命名空间