title: How to call certain functions depending on what generic type is passed in
body: <p>In the following code, I'm trying to make a short-hand function to get values of different types. It's obviously throwing a compile error. Does anyone know how I can achieve that? </p>
  
  <pre><code>private T Get&lt;T&gt;(string key)
          {
              if (typeof(T) == typeof(int))
              {
                  return this.httpContext.Session.GetInt32(key).Value;
              }
  
              if (typeof(T) == typeof(string))
              {
                  return this.httpContext.Session.GetString(key);
              }
  
              return this.httpContext.Session.GetInt32(key);
          }
  </code></pre>