title: Accessing a Private Constructor from Outside the Class in C#
body: <p>If I define a class with a private default constructor and a public constructor that has parameters, how can I access the private constructor?</p>
  <pre><code>public class Bob
  {
     public String Surname { get; set; }
  
     private Bob()
     { }
  
     public Bob(string surname)
     {
        Surname = surname;
     }
  }
  </code></pre>
  <p>I can access the private constructor via a static method on the class like this:</p>
  <pre><code>public static Bob GetBob()
  {
     return new Bob();
  }
  </code></pre>
  <p>I thought that I could access the private constructor via an extension method, since (according to my understanding) extension methods are translated so that they <em><strong>appear to be</strong></em> static methods on the class, but I can't:</p>
  <pre><code>static class Fred
  {
     public static Bob Bobby(this Bob bob)
     {
        return new Bob();
     }
  }
  </code></pre>
  <p>So, how can I access the private constructor?</p>
  <p>Thank you</p>
  <hr />
  <h1>EDIT:</h1>
  <p>The reason that I wanted to do this was that I wanted to create tests for one of our business classes, but not allow a consumer of this class to be able to instantiate an object incorrectly. I'm testing it, so I know (I hope!) under what circumstances the tests will fail. I'm still a testing n00b right now so my idea may or may not have been the &quot;wrong way&quot; of doing things.</p>
  <p>I've changed my testing strategy to just do things the way the a consumer of this class would, i.e. calling the public methods and if the public methods are OK, assuming that the private methods are OK. I would still prefer to test the private methods, but my boss <em>is</em> breathing down my neck on a deliverable :-(</p>