title: Converting different object lists into a DataTable using FastMember
body: <p>I have written a method that converts a generic list to a DataTable using <a href="http://nuget.org/packages/FastMember/" rel="nofollow" title="http://nuget.org/packages/FastMember/">FastMember</a> from NuGet.</p>
  
  <p>This is my code:</p>
  
  <pre><code>public  DataTable ConvertGenericListToDataTable(List&lt;CustomObject&gt; inputList)
  {
      var dt = new DataTable();
      using (var reader = ObjectReader.Create(inputList))
      {
           dt.Load(reader);
      }
      return dt;
  }
  
  
  var customObject = new List&lt;CustomObject&gt;();
  var dt = ListToDataTable.ConvertGenericListToDataTable(customObject);
  </code></pre>
  
  <p>Which works fine.
  Customobject is a custom object i have created, i have several different lists that i want to pass to my method: <code>List&lt;CustomobjectA&gt;</code> or <code>List&lt;CustomobjectB&gt;</code> and so on.
  Its not much of a problem writing a method for every type of list i want to convert to a DataTable, but this could end in repeating the same lines of code over and over again, this is something i obviously want to prevent</p>
  
  <p>I  tried changing the parameter's type to <code>List&lt;object&gt;</code> and <code>List&lt;dynamic&gt;</code>.
  Then my code won't compile because: "The best overloadmethod match for ConvertGenericListToDataTable has some invalid arguments".</p>
  
  <p>Is there a way i can pass a List of objects as a parameter without defining the exact type of the object ?</p>