simoneL
simoneL

Reputation: 622

Mark only one internal class as visible to other assemblies

I know the existance of the InternalsVisibleTo Attribute, which make all the internal classes visible to external assemblies.

In my case I have an Utilities project where all the classes should be visible to only one specific assembly. All but one class, which contains Extension methods that should be visible to all the other assemblies in the solution and not to the external projects.

Which is the best way to achieve this result?

Upvotes: 2

Views: 1691

Answers (2)

Roy Dictus
Roy Dictus

Reputation: 33149

Split them up. Put the common class in its own assembly.

There is no way to specify specific classes as being "internals visible to".

Upvotes: 2

Savvas Kleanthous
Savvas Kleanthous

Reputation: 2745

Well, one way to achieve this, if you are using an IDE capable of this, is to share the file with the class with the Extension methods. This way if you mark it as internal, and all other classes as public, then you can have access to the extension methods, but it is not public. Also, when you edit the extension method class, this will be reflected in all of your assemblies in your solution. In Visual studio, the way to achieve this is to right click your project and select Add -> Add Existing item:

enter image description here

And then find your file and select Add as link:

enter image description here

Please note that friend assemblies should be used mostly for debugging and testing purposes. Using them as a feature is a code smell.

Upvotes: 0

Related Questions