开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜