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

I know it is possible to change the visibility with:

using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("UnitTests")]

namespace Foobar
{
    internal class Foo
    {
      //...
    }
}

So, my test project can create a test for the class Foo. The problem is that I have many inner classes, and I do not want to pollute them with this expression assembly. Is there any other way to do this InternalsVisibleTo("UnitTests")for the whole project?

+4
source share
2 answers

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

, , , .

, : AssemblyInfo.cs "" .

+9

@CodeCaster,

AssemblyInfo.cs

""

.

[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: InternalsVisibleTo("UnitTests")]

.

[assembly: InternalsVisibleTo("Foo.Bar.UnitTests")]
+4

Source: https://habr.com/ru/post/1661468/


All Articles