title: How to use Switch...Case in generic type parameter in C#?
body: <p>I have a class where I am using <code>Generic Type Parameter</code> to dynamically use it. Right now, I am using <code>if..else</code> which works fine with my custom classes. I was wondering if I can use <code>switch..case</code> here. </p>
  
  <p>If data types are <code>decimal</code> or <code>int</code> then I can use <code>TypeCode</code> like this.</p>
  
  <pre><code>switch (Type.GetTypeCode(typeof(T)))
  {
      case TypeCode.Int32:
         break;
      case TypeCode.Decimal:
         break;
  }
  </code></pre>
  
  <p>But I have custom classes which I created and I want to use them. Below code works and trying to use <code>switch..case</code> if possible.</p>
  
  <p><strong>My Code:</strong> </p>
  
  <pre><code>void LogError&lt;T&gt;(T response, string orderId)
  {
      if (typeof(T) == typeof(QuoteResponse))
      {
          var quoteResponse = response as QuoteResponse;
  
          //Do something
      }
      else if (typeof(T) == typeof(CommitResponse))
      {
          var commitResponse = response as CommitResponse;
  
          //Do something
      }
      else if (typeof(T) == typeof(CancelResponse))
      {
          var cancelResponse = response as CancelResponse;
  
          //Do something
      }
      else if (typeof(T) == typeof(StatusResponse))
      {
          var statusResponse = response as StatusResponse;
  
          //Do something
      }
  }
  </code></pre>