title: Automatic type Conversion in C#
body: <p>I know that you could override an object's ToString() Method, so that everytime you call an object or pass it to a function that requires a String type it will be converted to a String.</p>
  
  <p>I have written several extension methods for object type 'object'</p>
  
  <pre><code>public static DateTime ToDate(this object date)
  {
      return DateTime.Parse(date.ToString());
  }
  
  public static int ToInteger(this object num)
  {
      return Int32.Parse(num.ToString());
  }
  
  public static long ToLong(this object num)
  {
      return Int64.Parse(num.ToString());
  }
  </code></pre>
  
  <p>so that I could just call them like this:</p>
  
  <pre><code>eventObject.Cost = row["cost"].ToString();
  eventObject.EventId = row["event_id"].ToLong();
  </code></pre>
  
  <p>However, what I want to accomplish is to convert the row objects which is of type 'object' to its correct type based on the property types on my 'eventObject'. So, I could call it like this:</p>
  
  <pre><code>eventObject.Cost = row["cost"];
  eventObject.EventId = row["event_id"];
  </code></pre>
  
  <p>The row is a DataRow if that matters.</p>