title: Is it possible to create instance of a class based on the typed method when call the method?
body: <p>I am not sure is it possible but I would like to create something like this:</p>
  <pre><code>public static T GetExceptions&lt;T&gt;(string id, string message)
  {
      var ex = new T //&lt;== Is this possible? Or in another way?
      {
         Id = id,
         StatusCode = HttpStatusCode.InternalServerError,
         Message = message
         Type = &quot;Type A&quot;
      };
              
      return ex;
  }
  </code></pre>
  <p>The ultimate goal is actually want to create a general method and returns custom exception class based on the different exception type input when calling this method.</p>
  <p>The main purpose I want to create a general method like this is because every of my exception class is having similar properties like Id, StatusCode, and Message, the only difference is the Type.</p>
  <p>So instead of copied the long code all over whenever I have to throw an exception. I was hoping that a general method can return me the exception, then all I have to do is throw it in the Main method.</p>