예제 #1
0
        public static ShengMapperTypeDescription Get(Type type)
        {
            if (type == null)
            {
                return(null);
            }

            if (_cacheList.Keys.Contains(type))
            {
                return(_cacheList[type]);
            }
            else
            {
                ShengMapperTypeDescription cacheCodon = new ShengMapperTypeDescription(type);

                Monitor.Enter(_cacheList);

                if (_cacheList.Keys.Contains(type) == false)
                {
                    _cacheList.Add(type, cacheCodon);
                }

                Monitor.Exit(_cacheList);

                return(cacheCodon);
            }
        }
예제 #2
0
        /// <summary>
        /// skipVirtual 是针对目标对象的
        /// </summary>
        /// <param name="sourceObject"></param>
        /// <param name="targetObject"></param>
        /// <param name="withProperties"></param>
        /// <param name="withoutProperties"></param>
        /// <param name="skipVirtual"></param>
        private static void SetValues(object sourceObject, object targetObject, string[] withProperties, string[] withoutProperties, bool skipVirtual)
        {
            if (sourceObject == null || targetObject == null)
            {
                throw new ArgumentNullException();
            }

            Type sourceObjectType = sourceObject.GetType();
            Type targetObjectType = targetObject.GetType();

            ShengMapperTypeDescription sourceObjectTypeCache = ShengMapperCache.Get(sourceObjectType);
            ShengMapperTypeDescription targetObjectCache     = ShengMapperCache.Get(targetObjectType);

            foreach (ShengMapperPropertyDescription sourceProperty in sourceObjectTypeCache.PropertyList)
            {
                if (withProperties != null && withProperties.Length > 0 && withProperties.Contains(sourceProperty.Name) == false)
                {
                    continue;
                }

                if (withoutProperties != null && withoutProperties.Length > 0 && withoutProperties.Contains(sourceProperty.Name))
                {
                    continue;
                }

                if (sourceProperty.CanRead == false)
                {
                    continue;
                }

                if (targetObjectCache.ContainsProperty(sourceProperty.Name) == false)
                {
                    continue;
                }

                if (skipVirtual && targetObjectCache.IsVirtual(sourceProperty.Name))
                {
                    continue;
                }

                object sourcePropertyValue = sourceObjectTypeCache.GetValue(sourceObject, sourceProperty.Name);
                targetObjectCache.SetValue(targetObject, sourceProperty.Name, sourcePropertyValue);
            }
        }