My friends just call me

Hiding classes and implementation in assemblies to the outside world is a good thing. This way you can only expose valid interfaces to the outside and have a bunch of helper classes/methods to the number-crunching, while being marked internal or private.

But there is this thing called unit-testing. You sometimes have internal classes that are being used in some context, but you might need to test them from you unit-testing assembly. Or you want to expose certain interfaces only to a limited assembly. In this case the friend comes in handy. Prior to .Net 2.0 this was not possible to do …

But .Net 2.0 introduced the friend-concept. To mark an assembly to be a friend of some other assembly just add:

[assembly: InternalsVisibleTo("Com.Acme.Testing")]

This way all internal classes/members of the assembly Com.Acme.Business can be called by the assembly Com.Acme.Testing.

Leave a Comment.