title: Generic Method Return Type as Type parameter
body: <p>I have an extension method that is working ok to cast string values into various types, which looks something like this:</p>
  
  <pre><code>public static T ToType&lt;T&gt; (this string value, T property)
      {
          object parsedValue = default(T);
          Type type = property.GetType();
  
          try
          {
              parsedValue = Convert.ChangeType(value, type);
          }
          catch (ArgumentException e)
          {
              parsedValue = null;
          }
  
          return (T)parsedValue;
      }
  </code></pre>
  
  <p>I'm unhappy about the way this looks when calling the method, however:</p>
  
  <pre><code>myObject.someProperty = stringData.ToType(myObject.someProperty);
  </code></pre>
  
  <p>Specifying the property just to obtain the property's type seems redundant.  I would rather use a signature like this:</p>
  
  <pre><code>public static T ToType&lt;T&gt; (this string value, Type type) { ... }
  </code></pre>
  
  <p>and have T end up to be the Type of type.  This would make calls much cleaner:</p>
  
  <pre><code>myObject.someProperty = stringData.ToType(typeof(decimal));
  </code></pre>
  
  <p>When I try to call this way, however, the editor complains that the return type of the extension method can't be infered from usage.  Can I link T to the Type argument?</p>
  
  <p>What am I missing?</p>
  
  <p>Thanks</p>