Esempio n. 1
0
        public static void copyFrom(object toVO, object from)
        {
            if (toVO == null || from == null)
            {
                return;
            }
            Type      toType = toVO.GetType();
            int       len    = 0;
            FieldInfo toInfo;
            object    value = null;

            if (from is ASObject)
            {
                ASObject fromData = (ASObject)from;
                string[] keys     = fromData.Keys.ToArray();
                len = keys.Count();
                for (int i = 0; i < len; i++)
                {
                    string name = keys[i];
                    toInfo = toType.GetField(name);
                    if (toInfo != null)
                    {
                        fromData.TryGetValue(name, out value);
                        setValue(toInfo, name, toVO, value);
                    }
                }

                return;
            }

            Type fromType = from.GetType();

            FieldInfo[] infos = fromType.GetFields(BindingFlags.Instance | BindingFlags.Public);
            len = infos.Length;
            for (int i = 0; i < len; i++)
            {
                FieldInfo info = infos[i];
                toInfo = toType.GetField(info.Name);
                if (toInfo != null)
                {
                    value = info.GetValue(from);

                    setValue(toInfo, info.Name, toVO, value);
                }
            }
        }
        public static void copyFrom(object obj, object from)
        {
            Type toType = obj.GetType();

            FieldInfo toInfo;
            object    value = null;

            if (from is ASObject)
            {
                ASObject fromData = (from as ASObject);
                string[] keys     = fromData.Keys.ToArray();

                foreach (string name in keys)
                {
                    toInfo = toType.GetField(name);
                    if (toInfo != null)
                    {
                        fromData.TryGetValue(name, out value);
                        setValue(toInfo, name, obj, value);
                    }
                }

                return;
            }

            Type fromType = from.GetType();

            FieldInfo[] infos = fromType.GetFields(BindingFlags.Instance | BindingFlags.Public);
            foreach (FieldInfo info in infos)
            {
                toInfo = toType.GetField(info.Name);
                if (toInfo != null)
                {
                    value = info.GetValue(from);

                    setValue(toInfo, info.Name, obj, value);
                }
            }
        }