title: Best design to convert a data object to a DataTable
body: <p>I need to convert different data objects implementing the same interface (e.g. IFoo) to a flat DataTable. My current implementation is to create a set of functions that take <code>IFoo</code> as input argument, cast IFoo to its class and then return a DataTable.</p>
  
  <p>E.g. for class <code>Apple</code>  I have the following function:</p>
  
  <pre><code>public DataTable AppleToDataTable (IFoo obj)
  {
      Apple apl = obj as Apple;
      // some conversion logic here.
  }
  </code></pre>
  
  <p>For class <code>Orange</code>, I have something similar :</p>
  
  <pre><code>public DataTable OrangeToDataTable (IFoo obj)
  {
      Orange org = obj as Orange;
      // some conversion logic here.
  }
  </code></pre>
  
  <p>I use a <code>delegate</code> to point to this set of the functions. In my config XML file, I have a list of key value pairs that associates my data object with the converter functions (the data objects and converter functions are not 1-to-1 mapping, i.e. for the same data object, I may want to convert it into different DataTables. Each DataTable only contains portion of the data).</p>
  
  <p>When I receive a <code>IFoo</code>, it contains a unique id which tells me which data object it is and then I use the mapping in the config file to send the data object to the correct function and get the DataTable.</p>
  
  <p>So my question is: Is there a better design to do this task? Any input is highly appreciated. Thank you very much!</p>