示例#1
0
        public List <T> ObjectToModel <T>(string key)
        {
            List <T>            lis  = new List <T>();
            List <IReadContext> rlis = ReadContext.ReadList(key);

            Type type = typeof(T);
            T    t2   = (T)type.Assembly.CreateInstance(type.FullName);

            PropertyInfo[] infos = type.GetProperties();

            foreach (IReadContext r in rlis)
            {
                t2 = (T)type.Assembly.CreateInstance(type.FullName);
                Dictionary <string, object> kv = r.ToDictionary();
                foreach (PropertyInfo info in infos)
                {
                    dynamic dyn = info.PropertyType.IsValueType ? Activator.CreateInstance(info.PropertyType) : null;

                    switch (info.PropertyType.FullName)
                    {
                    case "System.String":
                        dyn = ObjectToString(kv, info.Name);
                        break;

                    case "System.Double":
                        dyn = ObjectToDecimal(kv, info.Name);
                        break;

                    case "System.Decimal":
                        dyn = ObjectToDecimal(kv, info.Name);
                        break;

                    case "System.Int32":
                        dyn = ObjectToInt(kv, info.Name);
                        break;

                    case "System.DateTime":
                        dyn = ObjectToDate(kv, info.Name);
                        break;

                    case "System.Char":
                        dyn = ObjectToChar(kv, info.Name);
                        break;
                    }

                    info.SetValue(t2, dyn, null);
                }
                lis.Add(t2);
            }

            return(lis);
        }
示例#2
0
        public List <T> GetList <T>(IReadContext read, string key)
        {
            var      t     = typeof(T);
            List <T> nmlis = new List <T>();

            foreach (IReadContext r in read.ReadList(key))
            {
                T nm = GetObject <T>(r);//创建对象

                nmlis.Add(nm);
            }

            return(nmlis);
        }
示例#3
0
 public List <IReadContext> ReadList(string key)
 {
     return(rc.ReadList(key));
 }