访问dll方法
我为我的客户准备了一些 C# dll 来执行一些功能。
问题是我也使用相同的 dll。
我怎样才能让一些方法对他可用,而所有方法对我可用。
谢谢,
I prepared some C# dll for my customer that doing some functionality.
The thing is that I use also same dll.
How can I make some methods available to him and all methods available for me.
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用共享代码库
只需编译两个项目即可。一个包含您提供给客户的 DLL 源代码,另一个包含您自己保留的所有源代码。
提供 Web 服务
为客户提供 Web 服务以访问他们被允许访问的代码。
使用共享 DLL 中的
InternalsVisibleTo
属性internal
[ assembly:InternalsVisibleTo]
添加到共享 DLL请参阅:http://msdn.microsoft.com/en-us/library /system.runtime.compilerservices.internalsvisibletoattribute.aspx
Use a shared code base
Simply compile two projects. One contains the source for the DLL you are providing to the customer, and the other contains all the source, which you keep for yourself.
Provide a web service
Provide a web service for the customer to access the code that they are allowed to access.
Use the
InternalsVisibleTo
attribute in the shared DLLinternal
[assembly: InternalsVisibleTo]
to the shared DLLSee: http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.internalsvisibletoattribute.aspx
您必须编译程序集的两个版本。您分发给客户的版本需要完全排除您不希望他们访问的方法,否则无论您如何“隐藏”它们,都可以通过反射访问它们。
(假设您不希望对程序集进行签名)
You have to compile two versions of your assembly. The version you distribute to your cutomer needs to completely exclude the methods you don't want them to access, otherwise they'll be accessible through Reflection regardless of how you "hide" them.
(Assuming you don't want your assemblies to be signed)
您可以使用 C# 预处理器指令就像
#define
一样,从相同的代码库编译两个版本的库。然后将一个版本发送给您的客户,保留另一个版本。
You could use the C# preprocessor directives like
#define
to compile two versions of the library from the same code base.Then ship one version to your customer, keep the other version for yourself.