开发者

Can I make all public variables/methods/classes internal in Visual Studio at compile time?

开发者 https://www.devze.com 2022-12-26 10:56 出处:网络
I would like to make all my public variables variables/methods/classes internal when compiling my Visual Studio project. The source code would not change but when the compiled library is done, it shou

I would like to make all my public variables variables/methods/classes internal when compiling my Visual Studio project. The source code would not change but when the compiled library is done, it should only have internal access. Is this possible?

I have "InternalsVisibleTo("ClassLibrary") " set int开发者_Python百科he Assembly info file for all the projects, however, I would not like to run a replace all on "public " to "internal ". Does anyone know if there is away around this? So when I compile, build my project, the release project is only allowing internal access.

Thank you and have a nice day,

Joe


I think you have misunderstood the use of the InternalsVisibleTo attribute. It is used to allow code in another assembly to access types and members declared as internal.

Say you have AssemblyA, in which you have internal class SomeClass. Then you have AssemblyB. The code in AssemblyB cannot use SomeClass, since it is internal in AssemblyA. You can then, in AssemblyA, use InternalsVisibleTo to grant access for AssemblyB to use the internal types and members of AssemblyA.

If you simply want to make the code internal to AssemblyA, you will need to declare the types accordingly from the start; there are no shortcuts for that.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号