List to DataTable
<p>I want to convert List to DataTable(). I have List and I have properties as List and Dictonery inside that. How can I convert to ToDataTable().</p>

<p>My code is as follows From this code I can convert only System.Int,System.String but I am unable to convert Syste.Collections also. Actually I want the rows to be duplicated with every value of inner list or dictinery.</p>

<pre><code>public class Program 
{
    static void Main(string[] args)
    {
        Employee ee = new Employee();
        ee.Age = 98;
        ee.Name = "adfa";


        List&lt;string&gt; adad = new List&lt;string&gt;();
        adad.Add("adad");
        adad.Add("1212adad");
        adad.Add("59adad");

        Dictionary&lt;string, string&gt; dfasd = new Dictionary&lt;string, string&gt;();
        dfasd.Add("adad", "adfad");
        dfasd.Add("qwqq", "mnmn");

        ee.lstCer = adad;
        ee.kkj = dfasd;

        List&lt;Employee&gt; lschk = new List&lt;Employee&gt;();
        lschk.Add(ee);

        Program ps = new Program();
        DataTable dt = ps.ToDataTable(lschk); 
     }

     public DataTable ToDataTable&lt;T&gt;(IList&lt;T&gt; data)
     {
         PropertyDescriptorCollection properties =
            TypeDescriptor.GetProperties(typeof(T));
         DataTable table = new DataTable();


         foreach (PropertyDescriptor prop in properties)
         {

             table.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType);
         }

         DataRow row = null;

         foreach (T item in data)
         {

             foreach (PropertyDescriptor prop in properties)
             {

                 row[prop.Name] = prop.GetValue(item) ?? DBNull.Value;

             }
             table.Rows.Add(row);
         }
         return table;
     } 
}

public class Employee
{
    public string Name { get; set; }
    public int Age { get; set; }
    public List&lt;string&gt; lstCer { get; set; }
    public Dictionary&lt;string, string&gt; kkj { get; set; }
    public Array hh { get; set; }
}
</code></pre>
