gpt4 book ai didi

.net - 限制对 C#.NET 中的类库的访问

转载 作者:行者123 更新时间:2023-12-02 04:52:25 25 4
gpt4 key购买 nike

我有一个 C# 类库,将在 2 个不同的项目中使用。其中一个应该访问所有公共(public)类和方法,另一个应该只访问部分类和方法。

什么是最好的解决方案?

最佳答案

我认为最好的选择是 InternalsVisibleTo属性

Ordinarily, types and members with internal scope (in C#) and friend scope (in Visual Basic) are visible only in the assembly in which they are defined. The InternalsVisibleToAttribute attribute makes them also visible to the types in a specified assembly, which is known as a friend assembly. The attribute is applied at the assembly level. This means that it can be included at the beginning of a source code file, or it can be included in the AssemblyInfo file in a Visual Studio project

当然这不会阻止人们使用反射

调用您的方法

关于.net - 限制对 C#.NET 中的类库的访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18600491/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com