title: How to prevent access to a class from within a namespace?
body: <p>How can I prevent use of a class from outside its namespace in C#?</p>
  <p>For example, I have two namespaces. One defines a data model class, the other defines a data model class which inherits the first. The second namespace also defines a utility class which is the only class to be allowed to use the second data model class..</p>
  <pre><code>namespace A
  {
      public class ModelA {} // can be used by any class
  }
  
  namespace B
  {
      class ModelB : ModelA {} // can only be used by Utility
  
      public class Utility
      {
          public void DoSomething()
          {
              var item = new ModelB {};
              ...
          }
      }
  }
  </code></pre>
  <p>By implementing the following code in another class library or project, I would like the effect indicated by the comments...</p>
  <pre><code>namespace C
  {
      public class Stuff
      {
          public void DoThings()
          {
              var a = new ModelA(); // this should work
              var b = new ModelB(); // this should not work
          }
      }
  }
  </code></pre>