title: How to create type safety on a PrivateObject in C#
body: <p>I have discovered a fantastic way to unit test private methods. </p>
  
  <p>This is great except I don't like how the method name is typed in as a string. Is there a way to create a "safety net?" I want to type the method name so that the compiler can throw a compiler time error if the method does not exist on an object.</p>
  
  <p><strong>Private method:</strong></p>
  
  <pre><code>public class BankAccount
  {
      //Private method to test
      private bool VerifyAmount(double amount)
      {
          return (amount &lt;= 1000);
      }
  }
  </code></pre>
  
  <p><strong>Unit Test:</strong></p>
  
  <pre><code>[TestMethod()]        
  public void VerifyAmountTest()
  {
      //Using PrivateObject class
      PrivateObject privateHelperObject = new PrivateObject(typeof(BankAccount));                             
      double amount = 500F;
      bool expected = true;
      bool actual;
      actual = (bool)privateHelperObject.Invoke("VerifyAmount", amount);            
      Assert.AreEqual(expected, actual);            
  }
  </code></pre>
  
  <p>I know that some people think that we should not unit test private methods. That is not the purpose of this question so let's not discuss that question and stay on topic.</p>