public object Map(ResolutionContext context, IMappingEngineRunner mapper) { if (context.TypeMap.CustomMapper != null) { return MapUsingCustomMapper(context); } var profileConfiguration = mapper.ConfigurationProvider.GetProfileConfiguration(context.TypeMap.Profile); if (context.SourceValue == null && profileConfiguration.MapNullSourceValuesAsNull) { return null; } if (context.DestinationValue == null && context.InstanceCache.ContainsKey(context)) { return context.InstanceCache[context]; } return MapUsingMappingEngineRunner(context, mapper); } private static object MapUsingCustomMapper(ResolutionContext context) { context.TypeMap.BeforeMap(context.SourceValue, null); object mappedObject = context.TypeMap.CustomMapper(context); context.TypeMap.AfterMap(context.SourceValue, mappedObject); return mappedObject; } private static object MapUsingMappingEngineRunner(ResolutionContext context, IMappingEngineRunner mapper) { object mappedObject = context.DestinationValue ?? mapper.CreateObject(context.DestinationType); if (context.DestinationValue == null && context.SourceValue != null) { context.InstanceCache.Add(context, mappedObject); } context.TypeMap.BeforeMap(context.SourceValue, mappedObject); foreach (PropertyMap propertyMap in context.TypeMap.GetPropertyMaps()) { MapPropertyValue(context, mapper, mappedObject, propertyMap); } return mappedObject; }