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 Foo
. The problem is that I have a lot of internal classes and I don't want to dirty them with that assembly
expression. Is there another way of doing this InternalsVisibleTo("UnitTests")
for the whole project?
If a class or member is internal it´s ment to be used only within a given assembly. If you need access from outside the assembly make the class public.
A friend assembly is an assembly that can access another assembly's internal (C#) or Friend (Visual Basic) types and members.
The short answer is that it doesn't matter. Public methods of an internal class are internal. To the compiler, the internal/public method distinction only matters for public classes.
class OuterClass { ... class InnerClass { ... } } An instance of InnerClass can exist only within an instance of OuterClass and has direct access to the methods and fields of its enclosing instance. To instantiate an inner class, you must first instantiate the outer class.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With