Reference2 介面
更新:2007 年 11 月
擴充 VSLangProj 命名空間的 Reference 介面。
命名空間: VSLangProj2
組件: VSLangProj2 (在 VSLangProj2.dll 中)
語法
<GuidAttribute("4FFF24C5-5644-4A47-A48A-B74C3F1F8FC8")> _
Public Interface Reference2 _
Implements Reference
Dim instance As Reference2
[GuidAttribute("4FFF24C5-5644-4A47-A48A-B74C3F1F8FC8")]
public interface Reference2 : Reference
[GuidAttribute(L"4FFF24C5-5644-4A47-A48A-B74C3F1F8FC8")]
public interface class Reference2 : Reference
public interface Reference2 extends Reference
備註
VSProject 物件的 References 集合所傳回的 Reference 物件,同時支援 Reference 介面與 Reference2 介面。將這個物件轉型成 Reference2 就可以存取 Reference2 成員。
Reference2 定義了 VSLangProj 命名空間中的所有 Reference 成員,以及:
範例
下列範例將利用樣板建立新的專案、新增兩個參考並顯示它們的類型。
'Macro Editor
Imports VSLangProj
Sub NewProject()
Dim newName As String = InputBox("New project name:")
' Create a new project in the solution based on an existing
' project.
Dim newProject As Project = DTE.Solution.AddFromTemplate( _
"C:\TemplatePath\Template.vbproj", _
"C:\ProjectPath\" & newName, newName)
' Add a COM reference and display its type.
Dim vsProject As VSProject = CType(newProject.Object, VSProject)
Dim newRef As Reference
newRef = vsProject.References.Add("C:\WINNT\System32\msmask32.ocx")
MsgBox(GetRefTypeName(newRef))
' Add an Assembly reference and display its type, "Assembly".
newRef = vsProject.References.Add("C:\SomeProject\bin\SomeProject.dll")
MsgBox(GetRefTypeName(newRef))
End Sub
Private Function GetRefTypeName(ByVal ref As Reference) _
As String
Dim type As String
Select Case ref.Type
Case prjReferenceType.prjReferenceTypeActiveX
type = "COM"
Case prjReferenceType.prjReferenceTypeAssembly
type = "Assembly"
End Select
Return type
End Function
下列範例將建立參考屬性 (Property) 的簡式報表。
' Macro Editor
' Create a small report about a reference.
Imports VSLangProj
Function ReportReferences(ByVal aRef As Reference) As String
Dim report As String = ""
Dim type As String
' Each entry in the ArrayList will contain a label and a value.
Dim ht As System.Collections.ArrayList = _
New System.Collections.ArrayList()
With aRef
ht.Add(New String() {"Name", .Name})
ht.Add(New String() {"Description", .Description})
ht.Add(New String() {"Version", String.Format("{0}.{1}.{2}.{3}", _
.MajorVersion, .MinorVersion, .BuildNumber, .RevisionNumber)})
ht.Add(New String() {"Location", .ContainingProject.FullName})
Select Case .Type
Case prjReferenceType.prjReferenceTypeActiveX
type = "COM"
Case prjReferenceType.prjReferenceTypeAssembly
type = "Assembly"
End Select
ht.Add(New String() {"Type", type})
ht.Add(New String() {"Culture", .Culture})
End With
Dim datas() As String
For Each datas In ht
report &= datas(0) & ControlChars.Tab & datas(1) & ControlChars.CrLf
Next
Return report
End Function