Advertisement
Guest User

Neil Mosafi

a guest
Jul 7th, 2009
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.82 KB | None | 0 0
  1.         public object Map(ResolutionContext context, IMappingEngineRunner mapper)
  2.         {
  3.             if (context.TypeMap.CustomMapper != null)
  4.             {
  5.                 return MapUsingCustomMapper(context);
  6.             }
  7.  
  8.             var profileConfiguration = mapper.ConfigurationProvider.GetProfileConfiguration(context.TypeMap.Profile);
  9.             if (context.SourceValue == null && profileConfiguration.MapNullSourceValuesAsNull)
  10.             {
  11.                 return null;
  12.             }
  13.  
  14.             if (context.DestinationValue == null && context.InstanceCache.ContainsKey(context))
  15.             {
  16.                 return context.InstanceCache[context];
  17.             }
  18.  
  19.             return MapUsingMappingEngineRunner(context, mapper);
  20.         }
  21.  
  22.         private static object MapUsingCustomMapper(ResolutionContext context)
  23.         {
  24.             context.TypeMap.BeforeMap(context.SourceValue, null);
  25.             object mappedObject = context.TypeMap.CustomMapper(context);
  26.             context.TypeMap.AfterMap(context.SourceValue, mappedObject);
  27.             return mappedObject;
  28.         }
  29.  
  30.         private static object MapUsingMappingEngineRunner(ResolutionContext context, IMappingEngineRunner mapper)
  31.         {
  32.             object mappedObject = context.DestinationValue ?? mapper.CreateObject(context.DestinationType);
  33.  
  34.             if (context.DestinationValue == null && context.SourceValue != null)
  35.             {
  36.                 context.InstanceCache.Add(context, mappedObject);
  37.             }
  38.  
  39.             context.TypeMap.BeforeMap(context.SourceValue, mappedObject);
  40.             foreach (PropertyMap propertyMap in context.TypeMap.GetPropertyMaps())
  41.             {
  42.                 MapPropertyValue(context, mapper, mappedObject, propertyMap);
  43.             }
  44.  
  45.             return mappedObject;
  46.         }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement