title: How to convert value from object to Nullable<>
body: <p>I have some class with some properties and I want to convert values from string to type of this properties. And I have problem with conversion to nullable types. This is my method for converting:</p>
  
  <pre><code>public static object ChangeType(object value, Type type)
  {
      if (type.IsGenericType &amp;&amp; type.GetGenericTypeDefinition().Equals(typeof(Nullable&lt;&gt;)))
      {
          if (value == null)
          {
              return null;
          }
  
          var underlyingType = Nullable.GetUnderlyingType(type);
          var val = Convert.ChangeType(value, underlyingType);
          var nullableVal = Convert.ChangeType(val, type); // &lt;-- Exception here
          return nullableVal;
      }
  
      return Convert.ChangeType(value, type);
  }
  </code></pre>
  
  <p>I'm getting exception like this (for property of type int?): </p>
  
  <blockquote>
    <p><em>Invalid cast from 'System.Int32' to 'System.Nullable`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral,
    PublicKeyToken=b77a5c561934e089]]'.</em></p>
  </blockquote>
  
  <p>How can I convert from type to nullable type? 
  Thanks.</p>