public static TypeMappingDescription Get(Type type)
        {
            if (type == null)
            {
                return(null);
            }

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

                Monitor.Enter(_cacheList);

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

                Monitor.Exit(_cacheList);

                return(cacheCodon);
            }
        }
Exemple #2
0
        private static void SetValues(object sourceObject, object targetObject, string[] withProperties, string[] withoutProperties)
        {
            if (sourceObject == null || targetObject == null)
            {
                throw new ArgumentNullException();
            }

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

            TypeMappingDescription sourceObjectTypeCache = TypeMappingCache.Get(sourceObjectType);
            TypeMappingDescription targetObjectCache     = TypeMappingCache.Get(targetObjectType);

            foreach (PropertyMappingDescription 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;
                }

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