如果DLL可用,则调用函数?

时间:2022-04-14 19:31:18

I want to call managed code if and only if the currently executing assembly references it and has a match for that function name.

当且仅当当前正在执行的程序集引用它并且该函数名称匹配时,我想调用托管代码。

I have a function

我有一个功能

Public Function TestReadableProperties() As String

    ' Not sure where to go with this line
    ' Dim names = Reflection.Assembly.GetExecutingAssembly.GetReferencedAssemblies()


    Return bLib.bReflection.GetAllReadableProperties(Me)
End Function

if the bLib.dll is not present, then I don't want the project using this DLL to complain or crash. I'd like to not have warnings about conflicting versions of dependent assemblies. This code is nice to have for testing, but I'd like to remove the dependency on this library without removing functionality if the dependencies happen to match up.

如果bLib.dll不存在,那么我不希望使用此DLL的项目抱怨或崩溃。我想不要有关于依赖程序集的冲突版本的警告。这段代码很适合进行测试,但是如果依赖项恰好匹配,我想删除对这个库的依赖而不删除功能。

Is this possible?

这可能吗?

1 个解决方案

#1


Simple put your function call between a try and catch statement.

简单地在try和catch语句之间调用函数。

Public Function TestReadableProperties() As String
    Try
        Return bLib.bReflection.GetAllReadableProperties(Me)
    Catch
        ''// bLib is not available, let's return nothing
        Return Nothing
    End Try
End Function

Sorry for the funky comment, it's just to trick the highlighter to actually see it as a comment.

对于这个时髦的评论感到抱歉,它只是欺骗荧光笔实际上将其视为评论。

#1


Simple put your function call between a try and catch statement.

简单地在try和catch语句之间调用函数。

Public Function TestReadableProperties() As String
    Try
        Return bLib.bReflection.GetAllReadableProperties(Me)
    Catch
        ''// bLib is not available, let's return nothing
        Return Nothing
    End Try
End Function

Sorry for the funky comment, it's just to trick the highlighter to actually see it as a comment.

对于这个时髦的评论感到抱歉,它只是欺骗荧光笔实际上将其视为评论。