title: PropertyInfo.SetValue unable to convert string to Decimal
body: <p>I have a datatable which has columns of different datatypes(mostly int64 and string).
  I am trying to convert this datatable into list of objects.
  For which i am using these methods,</p>
  
  <pre><code>public static List&lt;T&gt; ConvertDataTable&lt;T&gt;(DataTable dt)
  {
   List&lt;T&gt; data = new List&lt;T&gt;();
   foreach (DataRow row in dt.Rows)
   {
    T item = GetItem&lt;T&gt;(row);
    data.Add(item);
   }
   return data;
  }
  </code></pre>
  
  <p>The below GetItem()(<code>pro.SetValue()</code> to be more precise) method throws an exception(<code>Object of type 'System.String' cannot be converted to type 'System.Decimal'</code>.) when trying to convert the <code>datacolumn</code> value which is of <code>string</code> to the class property of type <code>Decimal</code></p>
  
  <pre><code>private static T GetItem&lt;T&gt;(DataRow dr)
  {
   Type temp = typeof(T);
   T obj = Activator.CreateInstance&lt;T&gt;();
   foreach (DataColumn column in dr.Table.Columns)
   {
    foreach (PropertyInfo pro in temp.GetProperties())
    {
     if (pro.Name == column.ColumnName)
      pro.SetValue(obj, dr[column.ColumnName], null);
      else
       continue;
    }
   }
  return obj;
  }
  </code></pre>
  
  <p>Here  is <code>MyClass</code>
  Which is nothing but</p>
  
  <pre><code>public class AgriSales
  {
   public Int64 Id { get; set; }
   public string Type { get; set; }
   public Decimal Cost    { get; set; }
  }
  </code></pre>
  
  <p>Can someone guide me the right way to overcome the hurdle that i am facing?</p>