title: Return type of generic method
body: <p>I have a generic method which is to return an object of the generic type. Some code:</p>
  
  <pre><code>public static T Foo&lt;T&gt;(string value)
  {
      if (typeof(T) == typeof(String))
          return value;
  
      if (typeof(T) == typeof(int))
          return Int32.Parse(value);
  
      // Do more stuff
  }
  </code></pre>
  
  <p>I can see that the compiler might complain about this (<em>"Cannot convert type 'String' to 'T'"</em>), even if the code shouldn't cause any logical errors runtime. Is there any way to achieve what I'm looking for? Casting doesn't help...</p>