我有 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/