title: Nullable problems with Activator.CreateInstance and Convert.ChangeType
body: <p>I have a third party library which sets a given objects property using reflection as follows. (This is the simplified version)</p>
  
  <pre><code>public void Set(object obj, string prop, object value) {
      var propInf = obj.GetType().GetProperty(prop);
      value = Convert.ChangeType(value, propInf.PropertyType);
      propInf.SetValue(obj, value, null);
  }
  </code></pre>
  
  <p>And We have class with a nullable property</p>
  
  <pre><code>class Test
  {
      public int? X { get; set; }
  }
  </code></pre>
  
  <p>When I write the following code, it says it cannot convert <code>int</code> to <code>int?</code></p>
  
  <pre><code>var t = new Test();
  Set(t, "X", 1);
  </code></pre>
  
  <p>Since Nullable does not implement IConvertible it makes sense. Then I decided to write a method which returns the nullable version of a given value typed object.</p>
  
  <pre><code>public object MakeNullable(object obj) {
      if(obj == null || !obj.GetType().IsValueType)
          throw new Exception("obj must be value type!");
  
      return Activator.CreateInstance(
          typeof(Nullable&lt;&gt;).MakeGenericType(obj.GetType()), 
          new[] { obj });
  }
  </code></pre>
  
  <p>I hoped to use this method as follows.</p>
  
  <pre><code>var t = new Test();
  Set(t, "X", MakeNullable(1));
  </code></pre>
  
  <p>But it still says it cannot convert <code>int</code> to <code>int?</code>. When I debug <code>typeof(Nullable&lt;&gt;).MakeGenericType(obj.GetType())</code> equals <code>int?</code> but <code>Activator.CreateInstace</code> returns an <code>int</code> value not <code>int?</code></p>
  
  <p>So this is my case... Any help?</p>