title: get default value for a type
body: <p>I'm using a generic DataTable to List conversion method which I found on this site:  </p>
  
  <pre><code>private List&lt;T&gt; ConvertToList&lt;T&gt;(DataTable dt)
          {
              var columnNames = dt.Columns.Cast&lt;DataColumn&gt;()
                  .Select(c =&gt; c.ColumnName)
                  .ToList();
  
              var properties = typeof(T).GetProperties();
  
              return dt.AsEnumerable().Select(row =&gt;
              {
                  var objT = Activator.CreateInstance&lt;T&gt;();
  
                  foreach (var pro in properties)
                  {
                      if (columnNames.Contains(pro.Name))
                      {
                              pro.SetValue(objT, row[pro.Name], null);
                      }
                  }
  
                  return objT;
              }).ToList();
  
          }
  </code></pre>
  
  <p>it works great, except when I hit null values for integer fields in pro.SetValue. The reason it fails is because pro.SetValue will set a default value for a type if second parameter is null like this: pro.SetValue(objT, null,null).
  but my row[IdColumn] return empty object {} instead of null.
  The error I'm getting is: </p>
  
  <blockquote>
    <p>Object of type 'System.DBNull' cannot be converted to type
    'System.Nullable`1[System.Int32]'.</p>
  </blockquote>
  
  <p>when using <code>int?</code> 
  and </p>
  
  <blockquote>
    <p>Object of type 'System.DBNull' cannot be converted to type
    [System.Int32]'.</p>
  </blockquote>
  
  <p>when using <code>int</code>
  How do I handle this case?</p>