title: Casting string to generic type that is a string
body: <p>I'm writing a method to do a intelligent type conversion - using ToString() if the type parameter happens to be a string, otherwise casting but returning null if the cast doesn't work. Basically gets as much information out of <code>v</code> it can without throwing an exception.</p>
  
  <p>I check that <code>T</code> is indeed a <code>string</code> before I attempt the cast, but the compiler is still not a fan:</p>
  
  <pre><code>Cannot convert type 'string' to 'T'
  </code></pre>
  
  <p>And here's my method:</p>
  
  <pre><code>public T? Convert&lt;T&gt;(object v)
  {
      if (typeof(T) == typeof(string)) {
      return (T)v.ToString(); // Cannot convert type 'string' to 'T'  
      } else try {
        return (T)v;
      } catch (InvalidCastException) {
      return null;
      }
  }
  </code></pre>
  
  <p>Also let me know if this is some sort of unforgivable sin. I'm using it to deal with some data structures that could have mixed types.</p>