我正在尝试使用ASP.NET VB创建一个包含第三方产品的类库。
示例页面包含以下内容:
Imports Gurock.SmartInspect
SiAuto.Si.Enabled = True
SiAuto.Main.Color = Color.Green
SiAuto.Main.LogMessage("START LOGGING")
SiAuto.Main.Color = toggleCurrentMethodColour()
SiAuto在对象浏览器中定义为
Public NotInheritable Class SiAuto
Inherits System.Object
' Member of Gurock.SmartInspect
在将使用类库的项目中,我也想引用SiAuto:
Imports SouthViewSolutions.SmartInspect
(我的班级图书馆)
Log.EnterMethod(My.Application, method & ".Process")
(这是来自My Class Library。这个位有效)
If (SiAuto.Si.Level ...
最后一个语句想要使用SiAuto对象。如何将其提供给我的项目?
答案 0 :(得分:0)
包装第三方产品[所以我没有]必须在我的项目参考中包含第三方dll
然后,您无法通过调用代码访问第三方库的任何部分。只要您使用SiAuto
命名空间中的内容,您的代码就需要了解包含该命名空间的程序集。
你可以像这样(C#)将你想要访问的成员包装在你的库中:
Namespace YourLibrary
Public NotInheritable Class WrapperClass
Public Shared Property Level() As Integer
Get
Return SiAuto.Si.Level
End Get
Set
SiAuto.Si.Level = value
End Set
End Property
End Class
End Namespace
然后你可以从调用代码中访问它:
If (YourLibrary.WrapperClass.Level ...
请注意,如果Level
是SiAuto
命名空间中定义的类型(而不是此处演示的int
),则必须为此编写包装和转换代码太
请参阅示例Common Infrastructure's Common.Logging project,其目的是将代码与特定日志记录实现分离。您可以在不更改任何调用代码的情况下交换实际的日志记录实现,但为了实现这一点,他们编写了一个包含他们认为常见的每个日志记录方面的层。