示例#1
0
 /// <summary>
 /// IL动态代码(Emit),T转DataRow
 /// </summary>
 public static DataRow ToDataRow(this object obj)
 {
     var type    = obj.GetType();
     var table   = type.CreateTable();
     var builder = DataTableBuilder.CreateBuilder(type);
     {
         var dr = table.NewRow();
         builder.Build(obj, dr);
         return(dr);
     }
 }
示例#2
0
        /// <summary>
        /// IL动态代码(Emit),List转DataTable(Excel)
        /// </summary>
        public static DataTable ToExcelTable(this IList list)
        {
            var type    = list.GenericType();
            var table   = type.CreateExcelTable();
            var builder = DataTableBuilder.CreateBuilder(type, true);

            foreach (var item in list)
            {
                var dr = table.NewRow();
                builder.Build(item, dr);
                table.Rows.Add(dr);
            }
            return(table);
        }