title: Generic Type Converter - TypeConverter or Convert.ChangeType
body: <p>I am trying to convert from a String a a generic type. The generic type will be an Int32, Int64, Boolean, Double and so on ... I tried two approaches:</p>
  
  <pre><code>public static Boolean TryParse&lt;T&gt;(String source, out T value) {
  
    TypeConverter converter = TypeDescriptor.GetConverter(typeof(T));
  
    try {
  
      value = (T)converter.ConvertFromString(source);
      return true;
  
    } catch {
  
      value = default(T);
      return false;
  
    }
  
  }
  
  public static Boolean TryChangeType&lt;T&gt;(Object source, out T value) {
  
    try {
  
      Type type = Nullable.GetUnderlyingType(typeof(T)) ?? typeof(T);
  
      value = (T)Convert.ChangeType(source, type);
      return true;
  
    } catch {
  
      value = default(T);
      return false;
  
    }
  
  }
  </code></pre>
  
  <p>The second one is more generic as it accepts an Object.</p>
  
  <p>I am also considering passing an IFormatProvider in TryChangeType that would be used in Convert.ChangeType to resolve Culture issues and so on.</p>
  
  <p>Do you consider the second approach better?</p>
  
  <p>Any way I can improve my code?</p>