Example #1
0
        public PropertyMap GetExistingPropertyMapFor(MemberInfo destinationProperty)
        {
            if (!destinationProperty.DeclaringType.IsAssignableFrom(DestinationType))
            {
                return(null);
            }
            var propertyMap =
                PropertyMaps.FirstOrDefault(pm => pm.DestMember.Name.Equals(destinationProperty.Name));

            if (propertyMap != null)
            {
                return(propertyMap);
            }

            propertyMap =
                _inheritedMaps.FirstOrDefault(pm => pm.DestMember.Name.Equals(destinationProperty.Name));

            if (propertyMap == null)
            {
                return(null);
            }

            var propertyInfo = propertyMap.DestMember as PropertyInfo;

            if (propertyInfo == null)
            {
                return(propertyMap);
            }

            var baseAccessor = propertyInfo.GetMethod;

            if (baseAccessor.IsAbstract || baseAccessor.IsVirtual)
            {
                return(propertyMap);
            }

            var accessor = ((PropertyInfo)destinationProperty).GetMethod;

            if (baseAccessor.DeclaringType == accessor.DeclaringType)
            {
                return(propertyMap);
            }

            return(null);
        }