Exemple #1
0
        public static List <TParam> ToDbParam <TParam>(object obj, string sign, string prefix) where TParam : DbParameter
        {
            var convertMethod = DynamicMethodUtil.GetObjectToParamListMethod <TParam>(obj.GetType());
            var action        = (ObjectToParamListDelegate <TParam>)convertMethod.CreateDelegate(typeof(ObjectToParamListDelegate <TParam>));

            return(action(obj, sign, prefix));
        }
        private delegate T RowToEntityDelegate <T>(DataRow row);//将DataRow转为Entity的委托

        public static T ToEntity <T>(this DataRow @row)
        {
            if (@row == null)
            {
                return(default(T));
            }
            DynamicMethod method = DynamicMethodUtil.GetConvertToEntityMethod <T>();
            var           action = (RowToEntityDelegate <T>)method.CreateDelegate(typeof(RowToEntityDelegate <T>));

            return(action(@row));
        }
        private delegate List <T> TableToListDelegate <T>(DataTable table);//将Table转为List的委托

        public static List <T> ToList <T>(this DataTable @table)
        {
            if (@table == null || @table.Rows.Count <= 0)
            {
                return(new List <T>());
            }
            DynamicMethod method = DynamicMethodUtil.GetConvertToListMethod <T>();
            var           action = (TableToListDelegate <T>)method.CreateDelegate(typeof(TableToListDelegate <T>));

            return(action(@table));
        }