C#10: A namespace-scoped Access modifier

205 Views Asked by At

As in the title, I would love to see this in C#.

namespace PrivateStuff; //note: filescope namespace here!

public class PartiallyVisibleOutside
{
   public int A;
   namespace int B;
}

public class Test
{ 
    public PartiallyVisibleOutside NC {get; private set;}

    public void DoSmth()
    { 
        NC.A = 100000 + NC.B;  //OKAY til now!
        Console.Write(NC.A);
    }
}

//
namespace OUTSIDE;

public class OutsideClass 
{
   public PartiallyVisibleOutside Test;

   void DoSmth()
   {
      Test.A = 100; //OKAY
      Test.B = 100; //Compiletime-Error!
   }
}

Does smth like this exist? Or shall i open up a feature-request at C#

1

There are 1 best solutions below

7
Guru Stron On

There is no such feature and I think it is very niche thing to be implemented in near feature. Though you can simulate it by moving Test and PartiallyVisibleOutside into separate project (assembly) and marking B as internal.