public static DataTableEntityBuilder <T> CreateBuilder(DataRow dataRow)
        {
            DataTableEntityBuilder <T> dynamicBuilder = new DataTableEntityBuilder <T>();
            DynamicMethod method    = new DynamicMethod("DynamicCreateEntity", typeof(T), new Type[] { typeof(DataRow) }, typeof(T), true);
            ILGenerator   generator = method.GetILGenerator();
            LocalBuilder  result    = generator.DeclareLocal(typeof(T));

            generator.Emit(OpCodes.Newobj, typeof(T).GetConstructor(Type.EmptyTypes));
            generator.Emit(OpCodes.Stloc, result);

            for (int index = 0; index < dataRow.ItemArray.Length; index++)
            {
                PropertyInfo propertyInfo = typeof(T).GetProperty(dataRow.Table.Columns[index].ColumnName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase | BindingFlags.GetProperty);
                Label        endIfLabel   = generator.DefineLabel();
                if (propertyInfo != null && propertyInfo.GetSetMethod() != null)
                {
                    generator.Emit(OpCodes.Ldarg_0);
                    generator.Emit(OpCodes.Ldc_I4, index);
                    generator.Emit(OpCodes.Callvirt, isDBNullMethod);
                    generator.Emit(OpCodes.Brtrue, endIfLabel);
                    generator.Emit(OpCodes.Ldloc, result);
                    generator.Emit(OpCodes.Ldarg_0);
                    generator.Emit(OpCodes.Ldc_I4, index);
                    generator.Emit(OpCodes.Callvirt, getValueMethod);
                    generator.Emit(OpCodes.Unbox_Any, propertyInfo.PropertyType);
                    generator.Emit(OpCodes.Callvirt, propertyInfo.GetSetMethod());
                    generator.MarkLabel(endIfLabel);
                }
            }
            generator.Emit(OpCodes.Ldloc, result);
            generator.Emit(OpCodes.Ret);
            dynamicBuilder.handler = (Load)method.CreateDelegate(typeof(Load));
            return(dynamicBuilder);
        }
        public static List <T> ToList <T>(DataTable dt)
        {
            List <T> list = new List <T>();

            if (dt == null)
            {
                return(list);
            }
            if (dt.Rows.Count == 0)
            {
                return(list);
            }
            DataTableEntityBuilder <T> eblist = DataTableEntityBuilder <T> .CreateBuilder(dt.Rows[0]);

            foreach (DataRow info in dt.Rows)
            {
                list.Add(eblist.Build(info));
            }
            return(list);
        }