Reference3.Identity 屬性
取得參考的唯一識別項。
命名空間: VSLangProj80
組件: VSLangProj80 (在 VSLangProj80.dll 中)
語法
'宣告
ReadOnly Property Identity As String
Get
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 集合進行索引。
範例
此範例會將組件和 COM 參考加入至開啟的 Visual Basic 或 Visual C# 專案中,並且針對每個項目顯示 Identity 屬性。 若要將此範例當做增益集來執行,請參閱 HOW TO:編譯和執行 Automation 物件模型程式碼範例。
新增的參考之預設路徑:adodb.dll 為 <installation root>\Program Files\Microsoft.NET\Primary Interop Assemblies,以及 spcommon.dll 為 <installation root>\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 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。