Beispiel #1
0
        private T create <T>(DataRow dr, List <ResultCmd> cmds)
        {
            T t = Activator.CreateInstance <T>();

            foreach (ResultCmd c in cmds)
            {
                PropertyInfo pi;
                try
                {
                    pi = typeof(T).GetProperty(c.Property);
                }
                catch (Exception)
                {
                    throw new Exception(String.Format("{0} 对象没有属性 {1}", typeof(T).ToString(), c.Property));
                }
                ITypeHandler typeHandler = c.TypeHandler;
                if (typeHandler == null)
                {
                    typeHandler = TypeHandlerFactory.get(pi.PropertyType);
                }
                if (typeHandler != null)
                {
                    PropertyUtil.setValue(t, pi, typeHandler.getResult(dr, c.ColumnName));
                }
            }
            return(t);
        }
Beispiel #2
0
        private T create <T>(DataRow dr, Dictionary <String, PropertyInfo> propertys, Dictionary <String, ITypeHandler> typeHanlders)
        {
            T t = Activator.CreateInstance <T>();

            foreach (String key in propertys.Keys)
            {
                ITypeHandler typeHandler = getTypeHandler(typeHanlders, propertys[key].Name, propertys[key].PropertyType);
                if (typeHandler != null)
                {
                    PropertyUtil.setValue(t, propertys[key], typeHandler.getResult(dr, key));
                }
            }
            return(t);
        }