如何在插件中公开静态类而不分发该类的程序集和完整 MSIL?

发布于 2025-01-02 16:33:25 字数 152 浏览 3 评论 0原文

我有一个 C# 软件,它公开了插件接口。这些插件能够与创建某些在插件中使用的工具的工厂进行交互,但是我不想分发与插件接口的程序集一起编译的工厂代码。问题在于工厂不是一个接口,它是系统内部的静态工厂。可以这么说,我如何在不暴露工厂是什么的情况下暴露工厂的行为。

感谢您的帮助。

I have a software in c# that exposes an interface for plugins. The plugins come with the ability to interact with a factory that creates certain tools for use in the plugin, however I do not want to distribute the code for the factory compiled along with the assembly for the plugin interface. The problem is that the factory is not an interface, its a static factory interior to the system. How do I expose what the factory does, without exposing what the factory is, so to speak.

Thank you for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

寒尘 2025-01-09 16:33:25

由于工厂是任何插件的依赖项,因此您无法对其进行混淆/加密 - 如果您这样做,插件将无法使用工厂。您不必将 C# 源代码分发到工厂,但必须将已编译的程序集包含在工厂中,否则插件将无法工作。所以简短的回答是“你不能”。

Since the factory is a dependency of any plugins, you cannot obfuscate/encrypt it - plugins would not be able to use the factory if you did. You won't have to distribute the C# source to your factory, but you will have to include the compiled assembly with the factory, or the plugins will not work. So the short answer is "You can't".

陪你到最终 2025-01-09 16:33:25

您可以使用 ILMerge 来组合程序集为您提供软件的工厂。除此之外...您需要将工厂的代码放在某处,如果是 .NET,则意味着分发程序集。

You could use ILMerge to combine the assembly/assemblies for the factory with those for your software. Other than that... you are going to need to put the code for the factory somewhere, and if it is .NET that means distributing assemblies.

请止步禁区 2025-01-09 16:33:25

一个非常没有吸引力的选择是将代码包含到静态工厂中,并作为另一个程序集的资源进行加密,让另一个程序集解密并动态编译它,然后仅在必要时使用反射来访问它。当然这是一种可能性,尽管我很少推荐它。

如果您必须共享代码,更好的选择是实际上共享代码。

One very unappealing option is to include the code to your static factory encrypted as a resource to another assembly, have the another assembly decrypt and compile it dynamically and then only ever use reflection to access it where necessary. Of course this is a possibility, though I would rarely recommend it.

A better option if you have to share your code is to actually share the code.

明媚如初 2025-01-09 16:33:25

您可以将其包装在实现 IFactoryThing 的类中,这样,客户端代码将调用此接口。

但您仍然必须分发您的代码。

You could wrap it inside a class that implements IFactoryThing, this way, client code would do a call on this interface instead.

Still you would have to distribute your code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文