예제 #1
0
파일: Error.cs 프로젝트: hennadiilu/Nmap
        public static void MapValidationException_IfInheritanceMapIsNotForDerivedTypes(TypeMapBase map,
			PropertyMapBase propertyMap, TypeMapBase inheritanceMap)
        {
            Type baseType =
                ReflectionHelper.IsComplexEnumerable(propertyMap.SourcePropertyInfo.PropertyType)
                ? ReflectionHelper.GetEnumerableItemType(propertyMap.SourcePropertyInfo.PropertyType)
                : propertyMap.SourcePropertyInfo.PropertyType;

            Type type =
                (propertyMap.DestinationPropertyInfo != null)
                ? (ReflectionHelper.IsComplexEnumerable(propertyMap.DestinationPropertyInfo.PropertyType)
                    ? ReflectionHelper.GetEnumerableItemType(propertyMap.DestinationPropertyInfo.PropertyType)
                    : propertyMap.DestinationPropertyInfo.PropertyType)
                : null;

            if (!ReflectionHelper.IsAssignable(baseType, inheritanceMap.SourceType)
                || (type != null && !ReflectionHelper.IsAssignable(type, inheritanceMap.DestinationType))
                || (type == null && map.DestinationType != inheritanceMap.DestinationType))
            {
                throw new MapValidationException(string.Format(Resources.InheritanceMapIsNotForDerivedTypes3,
                    (inheritanceMap != null)
                    ? inheritanceMap.ToString()
                    : string.Empty, (propertyMap != null)
                        ? propertyMap.ToString()
                        : string.Empty, (map != null)
                            ? map.ToString()
                            : string.Empty), null);
            }
        }
예제 #2
0
        private static Action <TSource, TTarget, ReferenceTracker> CreateComplexMappingAction <TSource, TTarget>(Type sourceType, Type targetType,
                                                                                                                 Dictionary <SourceToTargetMap, MapTracker> existingMaps, MethodInfo complexPropertyMapMethod, PropertyMapBase propertyMap,
                                                                                                                 List <ReferenceTrackingType> referenceTrackingTypes)
        {
            var createMapFunc = complexPropertyMapMethod.MakeGenericMethod(
                sourceType, propertyMap.SourcePropertyInfo.PropertyType,
                targetType, propertyMap.TargetPropertyInfo.PropertyType);
            var complexPropertyMapping = (ComplexMapResult <TSource, TTarget>)createMapFunc.Invoke(null,
                                                                                                   new[] { propertyMap.SourcePropertyInfo, propertyMap.TargetPropertyInfo, existingMaps, propertyMap.ConfigObject });

            referenceTrackingTypes.AddRange(complexPropertyMapping.ReferenceTrackingTypes);
            return(complexPropertyMapping.MappingFunc);
        }
예제 #3
0
        private static Action <TSource, TTarget, ReferenceTracker> CreateListMapAction <TSource, TTarget>(Dictionary <SourceToTargetMap, MapTracker> existingMaps, PropertyMapBase propertyMap)
        {
            var sourceProperty = propertyMap.SourcePropertyInfo;
            var targetProperty = propertyMap.TargetPropertyInfo;

            var genericArguments = new Type[4 + sourceProperty.PropertyType.GenericTypeArguments.Length +
                                            targetProperty.PropertyType.GenericTypeArguments.Length];

            genericArguments[0] = typeof(TSource);
            genericArguments[1] = typeof(TTarget);
            genericArguments[2] = sourceProperty.PropertyType;
            genericArguments[3] = targetProperty.PropertyType;
            for (int i = 0; i < sourceProperty.PropertyType.GenericTypeArguments.Length; i++)
            {
                genericArguments[i + 4] = sourceProperty.PropertyType.GenericTypeArguments[i];
            }

            for (int i = 0; i < targetProperty.PropertyType.GenericTypeArguments.Length; i++)
            {
                genericArguments[i + 4 + sourceProperty.PropertyType.GenericTypeArguments.Length] =
                    targetProperty.PropertyType.GenericTypeArguments[i];
            }

            var bindFunc = typeof(ListMap).GetMethod(nameof(ListMap.Create),
                                                     BindingFlags.Static | BindingFlags.NonPublic)
                           .MakeGenericMethod(genericArguments);

            return((Action <TSource, TTarget, ReferenceTracker>)bindFunc.Invoke(null,
                                                                                new object[] { sourceProperty, targetProperty, existingMaps }));
        }
예제 #4
0
파일: Error.cs 프로젝트: hennadiilu/Nmap
 public static void MapValidationException_PropertyMapIsNotSupported(PropertyMapBase map)
 {
     throw new MapValidationException(string.Format(Resources.PropertyMapIsNotSupported1,
         (map != null) ? map.ToString() : string.Empty), null);
 }
예제 #5
0
파일: Error.cs 프로젝트: hennadiilu/Nmap
        public static void MapValidationException_IfPropertyMapIsNotForBothComplexEnumerableOrComplexTypes(
			TypeMapBase typeMap, PropertyMapBase propertyMap)
        {
            Type propertyType = propertyMap.SourcePropertyInfo.PropertyType;

            Type type = (propertyMap.DestinationPropertyInfo != null) ? propertyMap.DestinationPropertyInfo.PropertyType : null;

            if ((type == null && (ReflectionHelper.IsComplexEnumerable(propertyType)
                || ReflectionHelper.IsSimple(propertyType))) || (type != null && ((ReflectionHelper.IsComplexEnumerable(propertyType) && ReflectionHelper.IsComplex(type)) || (ReflectionHelper.IsComplex(propertyType) && ReflectionHelper.IsComplexEnumerable(type)) || ReflectionHelper.IsSimple(propertyType) || ReflectionHelper.IsSimple(type))))
            {
                throw new MapValidationException(string.Format(Resources.PropertyMapIsNotForBothComplexEnumerableOrComplexTypes2,
                    (propertyMap != null)
                    ? propertyMap.ToString()
                    : string.Empty, (typeMap != null)
                        ? typeMap.ToString()
                        : string.Empty), null);
            }
        }
예제 #6
0
파일: Error.cs 프로젝트: hennadiilu/Nmap
        public static void MapValidationException_IfPropertyMapHasMapperAndInheritanceMapsOrNothing(TypeMapBase typeMap,
			PropertyMapBase propertyMap, Action<object, object, TypeMappingContext> mapper, IEnumerable<TypeMapBase> inheritanceMaps)
        {
            if ((mapper != null && inheritanceMaps != null && inheritanceMaps.Count<TypeMapBase>() > 0)
                || (mapper == null && (inheritanceMaps == null || inheritanceMaps.Count<TypeMapBase>() == 0)))
            {
                throw new MapValidationException(string.Format(Resources.PropertyMapHasMapperAndInheritanceMapsOrNothing2,
                    (propertyMap != null) ? propertyMap.ToString()
                    : string.Empty, (typeMap != null)
                        ? typeMap.ToString()
                        : string.Empty), null);
            }
        }
예제 #7
0
파일: Error.cs 프로젝트: hennadiilu/Nmap
        public static void MapValidationException_IfPropertyMapDuplicated(TypeMapBase typeMap, PropertyMapBase propertyMap,
			IEnumerable<PropertyMapBase> propertyMaps)
        {
            if (propertyMaps.Count((PropertyMapBase m) => m.SourcePropertyInfo == propertyMap.SourcePropertyInfo
                || m.DestinationPropertyInfo == propertyMap.DestinationPropertyInfo) > 1)
            {
                throw new MapValidationException(string.Format(Resources.PropertyMapDuplicated2,
                    (propertyMap != null) ? propertyMap.ToString() : string.Empty,
                    (typeMap != null) ? typeMap.ToString() : string.Empty), null);
            }
        }