Exemplo n.º 1
0
        /// <summary>
        /// 对 <see cref="Profile"/> 对象进行重建。
        /// </summary>
        /// <param name="profile"></param>
        /// <returns></returns>
        public static dynamic Rebuild(Profile profile)
        {
            using (var objectPoll = new ObjectPoll())
            {
                if (profileType == null)
                {
                    profileType = BuildProfileProxyType(profile.GetType(), assemblyList);
                }

                return(CloneProxyObj(profile, profileType, objectPoll));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 对要生成的表进行重建。
        /// </summary>
        /// <param name="tables"></param>
        /// <returns></returns>
        public static List <dynamic> Rebuild(List <Table> tables)
        {
            using (var objectPoll = new ObjectPoll())
            {
                var result = new List <dynamic>();
                if (proxyType == null)
                {
                    proxyType = BuildSchemaProxyType(assemblyList);
                }

                foreach (var table in tables)
                {
                    var newtable = CloneProxyObj(table, proxyType.TableType, objectPoll);
                    result.Add(newtable);
                }

                return(result);
            }
        }
Exemplo n.º 3
0
        private static object CloneProxyObj(object source, Type objType, ObjectPoll objectPoll)
        {
            if (source == null)
            {
                return(null);
            }

            var result = objType.New();

            objectPoll.Push(result);
            objType = result.GetType();

            var pid = objType.GetProperty("_ID");

            if (pid != null)
            {
                var idvalue = source.GetType().GetProperty("_ID").FastGetValue(source);
                pid.FastSetValue(result, idvalue);
            }

            foreach (var property in source.GetType().GetProperties())
            {
                if (property.IsDefined <DisGenerateAttribute>())
                {
                    continue;
                }

                var p = objType.GetProperty(property.Name);
                if (p.Name == "_ID")
                {
                    continue;
                }

                var value = property.FastGetValue(source);
                var list  = value as IList;
                if (list != null)
                {
                    var newlist = p.PropertyType.New <IList>();
                    var eleType = p.PropertyType.GetEnumerableElementType();
                    foreach (var item in list)
                    {
                        object newobj = null;
                        if (!objectPoll.Find(item, ref newobj))
                        {
                            newobj = CloneProxyObj(item, eleType, objectPoll);
                        }

                        newlist.Add(newobj);
                    }

                    value = newlist;
                }
                else if (!p.PropertyType.IsValueType && p.PropertyType != typeof(string))
                {
                    if (!objectPoll.Find(value, ref value))
                    {
                        value = CloneProxyObj(value, p.PropertyType, objectPoll);
                    }
                }

                p.FastSetValue(result, value);
            }

            return(result);
        }