views:

41

answers:

1

Hi,

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 inthe 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

+1  A: 

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.

Fredrik Mörk
Thanks for the feedback.
Joe