抱歉,我本来希望粘贴此评论,但 SO 阻止我这样做。
据我所知,VB还没有添加C# Aliasing功能,但是你关于VB.Net中没有解决方案的说法是不正确的。
您引用的 2011 年帖子指出您可以使用反射作为解决方法。我认为最简单的途径是选择您想要智能感知支持的 DLL,并添加对该 DLL 的引用。然后,您可以使用 Reflection.Assembly.LoadFile 获取对第二个 DLL 的引用,并在该实例上使用 CreateInstance 方法创建对所需类的对象引用。您可以使用后期绑定来处理该类实例。或者,您可以使用反射来获取所需的 MethodInfo's/PropertyInfo's/等等。并通过它们来处理类实例,但我认为这比使用后期绑定要做更多的工作。
编辑添加示例。
Sub Test()
' assume you chose Version 2 as to reference in your project
' you can create an instance of its classes directly in your code
' with full Intellisense support
Dim myClass1V2 As New CommonRootNS.Class1
' call function Foo on this instance
Dim resV2 As Int32 = myClass1V2.foo
' to get access to Version 1, we will use Reflection to load the Dll
' Assume that the Version 1 Dll is stored in the same directory as the exceuting assembly
Dim path As String = IO.Path.GetDirectoryName(Reflection.Assembly.GetExecutingAssembly.Location)
Dim dllVersion1Assembly As Reflection.Assembly
dllVersion1Assembly = Reflection.Assembly.LoadFile(IO.Path.Combine(path, "Test DLL Version 1.dll"))
' now create an instance of the Class1 from the Version 1 Dll and store it as an Object
Dim myClass1V1 As Object = dllVersion1Assembly.CreateInstance("CommonRootNS.Class1")
' use late binding to call the 'foo' function. Requires Option Strict Off
Dim retV1 As Int32 = myClass1V1.foo
End Sub
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
247 次 |
| 最近记录: |