c# - 从另一个 dll、C# 重新加载 dll 函数

标签 c# dll

我有 2 个非托管 dll,它们具有完全相同的一组功能(但逻辑略有不同)。

如何在运行时在这 2 个 ddl 之间切换?

现在我有:

[DllImport("one.dll")]
public static extern string _test_mdl(string s);

最佳答案

在此处扩展现有答案。您评论说您不想更改现有代码。您不必那样做。

[DllImport("one.dll", EntryPoint = "_test_mdl")]
public static extern string _test_mdl1(string s);

[DllImport("two.dll", EntryPoint = "_test_mdl")]
public static extern string _test_mdl2(string s);

public static string _test_mdl(string s)
{
    if (condition)
        return _test_mdl1(s);
    else
        return _test_mdl2(s);
}

您继续在现有代码中使用 _test_mdl,并将 if 语句放入该方法的新版本中,调用正确的底层方法。

关于c# - 从另一个 dll、C# 重新加载 dll 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3186866/

相关文章:

c# - IValueConverter 的最佳实践是什么?

c# - 如何使用 TWILIO ASP.Net Web API 发送和验证 OTP

c# - 在 Server 2008 x64 上安装 VB6 运行时

c++ - Delphi:使用调试器调用 C dll 函数需要 15 秒,没有调试器需要 0.16 秒。为什么?

c# - 将字符串作为 PChar 从 CSharp 传递到 Delphi DLL

visual-studio - 如何在 Visual Studio 中编译项目而不在构建后运行?

c# - 高斯平滑公式应用

c# - WPF NotifyIcon不触发MouseEnter事件(显示工具提示时如何更新NotifyIcon View 模型)

c# - 命名函数定义范围

windows - 在 Windows 7 上编译 Fortran .dll(免费)?