Clear visibility for "internal" members

I recently read about sharing code with .NET assemblies and came across a good suggestion from this post : "Reduce the number of your .NET assemblies to a strict minimum."

I could not agree more! And one of the reasons that I personally see most often is that people just want to isolate part of the code, so they make types / methods internal and put them in a separate project.

There are many other reasons (valid and not) for splitting code into multiple assemblies, but if you want to isolate components / APIs while still in the same library, how can you do this?

namespace MyAssembly.SomeApiInternals
{
     //Methods from this class should not 
     //be used outside MyAssembly.SomeApiInternals
     internal class Foo
     {              
          internal void Boo() { }
     }
}

namespace MyAssembly.AnotherPart
{
     public class Program
     {              
          public void Test() 
          {
               var foo = MyAssembly.SomeApiInternals.Foo();
               foo.Boo(); //Ok, not a compiler error but some red flag at least 
          }
     }
}             

/ / , ?

( , .)

!

+3
2

, ILMerge ...

+3

NDepend CQL, , , . . ( - NDepend? )

+2

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


All Articles