I’m refactoring some code I didn’t write, that contains business logic and proprietary algorithms I don’t want to expose. All the code is currently marked as internal; for testing purposes, and to ensure I don’t break existing clients/services, I wanted to switch them to use interfaces, and implement those interfaces.
I’ve marked my classes as internal and their members as protected internal, and my interfaces as internal, but to use the internal interfaces, I’ve had to make several of my properties public.
I believe, and with some limited testing, seemed to have proven that only friend assemblies, and classes in my assembly, can use these internal interfaces and classes.
As long as both the class, and interface remain internal, even if some of the methods and the properties are marked public, will they be exposed at all?
It doesn’t seem so, but I’m looking for anything I might have missed.
If you mean protected as in a using assembly can’t directly use them, then yes, if the
interfaceandclassare markedinternal, then they won’t be visible outside the assembly. Think of the access level on the interfaces and members as being separate locks to get through.If you can see the
interfaceat its access level, then you can store a reference to it, and then if you can see the properties/methods at their access levels, then you can call/set/get them.Keep in mind, though, as @phoog points out that
protected internalis a bit looser thaninternal.All this said, if your
internalclass implements apublicinterface, and those properties are part of apublicinterface as well, they could be visible… But that’s really getting obscure…In the above, you could refer to the class
InvisibleClassthrough anIVisiblereference in a different assembly if you could find a way to construct or receive a reference to it (for instance, if it were returned from a factory method inside of the original assembly).All this aside, if your question is that you want to avoid them from being examined through a decompiler, reflection, etc, that’s a different question…