Convert IEnumerable to HTML table string My code can generate HTML table strings well, but it depends on JSON.NET.

I'm converting IEnumerable to an HTML table string using Json.NET but I think I shouldn't.

void Main()
{
    var datas = new[] { new {Name="Test"} };
    var array = datas.ToArray().ToHtmlTable(); //Run Success
    var set = datas.ToHashSet().ToHtmlTable();//Run Succes
    var list = datas.ToList().ToHtmlTable(); //Run Succes
    var enums = datas.AsEnumerable().ToHtmlTable(); //Run Succes
}

public static class HTMLTableHelper
{
    public static string ToHtmlTable(this IEnumerable enums)
    {
        return ToHtmlTableConverter(enums);
    }

    public static string ToHtmlTable(this System.Data.DataTable dataTable)
    {
        return ConvertDataTableToHTML(dataTable);
    }

    private static string ToHtmlTableConverter(object enums)
    {
        var jsonStr = JsonConvert.SerializeObject(enums);
        var data = JsonConvert.DeserializeObject&lt;System.Data.DataTable&gt;(jsonStr);
        var html = ConvertDataTableToHTML(data);
        return html;
    }

    private static string ConvertDataTableToHTML(System.Data.DataTable dt)
    {
        var html = new StringBuilder("&lt;table&gt;");

        //Header
        html.Append("&lt;thead&gt;&lt;tr&gt;");
        for (int i = 0; i &lt; dt.Columns.Count; i++)
            html.Append("&lt;th&gt;" + dt.Columns[i].ColumnName + "&lt;/th&gt;");
        html.Append("&lt;/tr&gt;&lt;/thead&gt;");

        //Body
        html.Append("&lt;tbody&gt;");
        for (int i = 0; i &lt; dt.Rows.Count; i++)
        {
            html.Append("&lt;tr&gt;");
            for (int j = 0; j &lt; dt.Columns.Count; j++)
                html.Append("&lt;td&gt;" + dt.Rows[i][j].ToString() + "&lt;/td&gt;");
            html.Append("&lt;/tr&gt;");
        }

        html.Append("&lt;/tbody&gt;");
        html.Append("&lt;/table&gt;");
        return html.ToString();
    }
}


I think it is bad because SerializeObject to string could be DeserializeObject to DataTable is a waste of efficiency.

var jsonStr = JsonConvert.SerializeObject(enums);
var data = JsonConvert.DeserializeObject&lt;System.Data.DataTable&gt;(jsonStr);


I want to remove dependencies on JSON.NET because it can reduce the size of the library.

Do you think I should replace them with something else if there is a better way?
I can use reflection to solve it:

void Main()
{
    var datas = new[] { new {Name="Test1",Value="Test2"} };
    var array = datas.ToArray().ToHtmlTable(); //Run Success
    var set = datas.ToHashSet().ToHtmlTable();//Run Succes
    var list = datas.ToList().ToHtmlTable(); //Run Succes
    var enums = datas.AsEnumerable().ToHtmlTable(); //Run Succes
}

public static class HTMLTableHelper
{
    public static string ToHtmlTable&lt;T&gt;(this IEnumerable&lt;T&gt; enums)
    {
        var type = typeof(T);
        var props = type.GetProperties();
        var html = new StringBuilder("&lt;table&gt;");

        //Header
        html.Append("&lt;thead&gt;&lt;tr&gt;");
        foreach (var p in props)
            html.Append("&lt;th&gt;" + p.Name + "&lt;/th&gt;");
        html.Append("&lt;/tr&gt;&lt;/thead&gt;");

        //Body
        html.Append("&lt;tbody&gt;");
        foreach (var e in enums)
        {
            html.Append("&lt;tr&gt;");
            props.Select(s =&gt; s.GetValue(e)).ToList().ForEach(p =&gt; {
                html.Append("&lt;td&gt;" + p + "&lt;/td&gt;");
            }); 
            html.Append("&lt;/tr&gt;");
        }

        html.Append("&lt;/tbody&gt;");
        html.Append("&lt;/table&gt;");
        return html.ToString();
    }
}




&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Name&lt;/th&gt;&lt;th&gt;Value&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Test1&lt;/td&gt;&lt;td&gt;Test2&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;