Question

Before deploying my project, I would like to set all public methods to internal methods. Does someone know a built-in function in Visual Studio or an external tool to do such tasks?

Was it helpful?

Solution

With some trivial refactoring, ILMerge can work here. ILMerge can merge multiple assemblies into one, and change the accessibility of everything that is not part of the primary assembly to internal. By separating your current project into two projects (a library containing all the code, and a helper executable that does nothing but forward to the real code in the library), you can, after a build, merge them back into a single file, in which all the library bits are no longer public.

OTHER TIPS

If you have properties/methods public for test reasons you should have a look at Brad Wilsons blog: Testable Object Pattern

This way you don't have to switch, everything stays internal in development.

Or have a look at Jon Skeets suggestion on InternalsVisibleTo

I can only think of two reasons you would want to do this:

  • Security. In this case you have the wrong idea: access modifiers are not a security mechanism. They are a design concern, describing how an API presents itself. Any debugger will still give access to all your methods, regardless of their access modifiers.

  • You have another assembly that you use during development that should have full access. In this case you can leave everything internal and make it a friend assembly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top