Denr2 Denr2 - 1 year ago 190
C# Question

Is it possible to make all internal classes visible to another assembly in C# with some configuration?

I know that is possible change the visibility with:

using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("UnitTests")]

namespace Foobar
internal class Foo

So my test project can create the test for the class
. The problem is that I have a lot of internal classes and I don't want to dirty them with that
expression. Is there another way of doing this
for the whole project?

Answer Source

The [InternalsVisibleTo] attribute is an assembly-level attribute, meaning that if you define it once, it already applies to the entire assembly.

So that line you show only needs to be included only once in your project to apply to all internal types.

I'd recommend moving it to where the other assembly-level attributes are specified: in the AssemblyInfo.cs file in the Properties folder of the project.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download