Exemplo n.º 1
0
        public TDestination Map <TSource, TDestination>(TSource source, Action <IMappingOperationOptions <TSource, TDestination> > opts)
        {
            var types = TypePair.Create(source, typeof(TSource), typeof(TDestination));

            var key = new TypePair(typeof(TSource), typeof(TDestination));

            var typedOptions = new MappingOperationOptions <TSource, TDestination>(ServiceCtor);

            opts(typedOptions);

            var mapRequest = new MapRequest(key, types, typedOptions.InlineConfiguration);

            var func = ConfigurationProvider.GetMapperFunc <TSource, TDestination>(mapRequest);

            var destination = default(TDestination);

            typedOptions.BeforeMapAction(source, destination);

            var context = new ResolutionContext(typedOptions, this);

            destination = func(source, destination, context);

            typedOptions.AfterMapAction(source, destination);

            return(destination);
        }
Exemplo n.º 2
0
 public ResolutionContext(object source, object destination, TypePair types, MappingOperationOptions options, IRuntimeMapper mapper)
 {
     SourceValue      = source;
     DestinationValue = destination;
     Options          = options;
     Mapper           = mapper;
     Types            = types;
 }
Exemplo n.º 3
0
        private object MapCore(object source, Type sourceType, Type destinationType, MappingOperationOptions options)
        {
            TypeMap typeMap = ConfigurationProvider.ResolveTypeMap(source, null, sourceType, destinationType);

            var context = new ResolutionContext(typeMap, source, sourceType, destinationType, options, this);

            return(((IMappingEngineRunner)this).Map(context));
        }
Exemplo n.º 4
0
 public ResolutionContext(TypeMap typeMap, object source, object destination, Type sourceType,
                          Type destinationType, MappingOperationOptions options, IMappingEngine engine)
     : this(Empty, source, destination, sourceType, destinationType, typeMap)
 {
     InstanceCache = new Dictionary <ResolutionContext, object>();
     Options       = options;
     Engine        = engine;
 }
Exemplo n.º 5
0
        public object Map(object source, Type sourceType, Type destinationType, Action <IMappingOperationOptions> opts)
        {
            var options = new MappingOperationOptions();

            opts(options);

            return(MapCore(source, sourceType, destinationType, options));
        }
Exemplo n.º 6
0
        private object MapCore(object source, object destination, Type sourceType, Type destinationType,
                               MappingOperationOptions options)
        {
            TypeMap typeMap = _configurationProvider.ResolveTypeMap(source, destination, sourceType, destinationType);

            var context = new ResolutionContext(typeMap, source, destination, sourceType, destinationType, options, _engine);

            return(_engine.Map(context));
        }
Exemplo n.º 7
0
 public ResolutionContext(TypeMap typeMap, object source, object destination, Type sourceType, Type destinationType, MappingOperationOptions options)
 {
     TypeMap          = typeMap;
     SourceValue      = source;
     DestinationValue = destination;
     AssignTypes(typeMap, sourceType, destinationType);
     InstanceCache = new Dictionary <ResolutionContext, object>();
     Options       = options;
 }
Exemplo n.º 8
0
        public TDestination Map <TSource, TDestination>(TSource source, Action <IMappingOperationOptions <TSource, TDestination> > opts)
        {
            Type modelType       = typeof(TSource);
            Type destinationType = typeof(TDestination);

            var options = new MappingOperationOptions <TSource, TDestination>();

            opts(options);

            return((TDestination)MapCore(source, modelType, destinationType, options));
        }
Exemplo n.º 9
0
        private TDestination MapWithOptions <TSource, TDestination>(TSource source, TDestination destination, Action <IMappingOperationOptions <TSource, TDestination> > opts,
                                                                    Type sourceType = null, Type destinationType = null)
        {
            var typedOptions = new MappingOperationOptions <TSource, TDestination>(DefaultContext.Options.ServiceCtor);

            opts(typedOptions);
            typedOptions.BeforeMapAction?.Invoke(source, destination);
            destination = MapCore(source, destination, new ResolutionContext(typedOptions, this), sourceType, destinationType);
            typedOptions.AfterMapAction?.Invoke(source, destination);
            return(destination);
        }
Exemplo n.º 10
0
        public object Map(object source, object destination, Type sourceType, Type destinationType, Action <IMappingOperationOptions> opts)
        {
            TypeMap typeMap = ConfigurationProvider.FindTypeMapFor(source, sourceType, destinationType);

            var options = new MappingOperationOptions();

            opts(options);

            var context = new ResolutionContext(typeMap, source, destination, sourceType, destinationType, options);

            return(((IMappingEngineRunner)this).Map(context));
        }
Exemplo n.º 11
0
        TDestination IMapper.Map <TSource, TDestination>(TSource source, TDestination destination, Action <IMappingOperationOptions <TSource, TDestination> > opts)
        {
            var typedOptions = new MappingOperationOptions <TSource, TDestination>(_inner.ServiceCtor);

            opts(typedOptions);

            typedOptions.BeforeMapAction(source, destination);

            destination = _inner.Map(source, destination, this);

            typedOptions.AfterMapAction(source, destination);

            return(destination);
        }
Exemplo n.º 12
0
        TDestination IMapper.Map <TSource, TDestination>(TSource source, TDestination destination, Action <IMappingOperationOptions <TSource, TDestination> > opts)
        {
            var types = TypePair.Create(source, destination, typeof(TSource), typeof(TDestination));

            var func = _configurationProvider.GetMapperFunc <TSource, TDestination>(types);

            var typedOptions = new MappingOperationOptions <TSource, TDestination>(_serviceCtor);

            opts(typedOptions);

            var context = new ResolutionContext(source, destination, types, typedOptions, this);

            return(func(source, destination, context));
        }
Exemplo n.º 13
0
        object IMapper.Map(object source, Type sourceType, Type destinationType, Action <IMappingOperationOptions> opts)
        {
            var types = TypePair.Create(source, null, sourceType, destinationType);

            var func = _configurationProvider.GetUntypedMapperFunc(new MapRequest(new TypePair(sourceType, destinationType), types));

            var options = new MappingOperationOptions(_serviceCtor);

            opts(options);

            var context = new ResolutionContext(source, null, types, options, this);

            return(func(source, null, context));
        }
Exemplo n.º 14
0
 public ResolutionContext(TypeMap typeMap, object source, object destination, Type sourceType,
                          Type destinationType, MappingOperationOptions options, IMappingEngine engine)
 {
     TypeMap          = typeMap;
     SourceValue      = source;
     DestinationValue = destination;
     if (typeMap != null)
     {
         SourceType      = typeMap.SourceType;
         DestinationType = typeMap.DestinationType;
     }
     else
     {
         SourceType      = sourceType;
         DestinationType = destinationType;
     }
     InstanceCache = new Dictionary <ResolutionContext, object>();
     Options       = options;
     Engine        = engine;
 }
Exemplo n.º 15
0
        TDestination IMapper.Map <TSource, TDestination>(TSource source, Action <IMappingOperationOptions <TSource, TDestination> > opts)
        {
            var types = TypePair.Create(source, null, typeof(TSource), typeof(TDestination));

            var func = _configurationProvider.GetMapperFunc <TSource, TDestination>(types);

            var destination = default(TDestination);

            var typedOptions = new MappingOperationOptions <TSource, TDestination>(_serviceCtor);

            opts(typedOptions);

            typedOptions.BeforeMapAction(source, destination);

            var context = new ResolutionContext(typedOptions, this);

            destination = func(source, destination, context);

            typedOptions.AfterMapAction(source, destination);

            return(destination);
        }
Exemplo n.º 16
0
 public ResolutionContext(TypeMap typeMap, object source, Type sourceType, Type destinationType, MappingOperationOptions options)
     : this(typeMap, source, null, sourceType, destinationType, options)
 {
 }
Exemplo n.º 17
0
 public ResolutionContext(MappingOperationOptions options, IRuntimeMapper mapper)
 {
     Options = options;
     Mapper  = mapper;
 }
Exemplo n.º 18
0
 public Mapper(IConfigurationProvider configurationProvider, Func <Type, object> serviceCtor)
 {
     _configurationProvider = configurationProvider;
     _serviceCtor           = serviceCtor;
     _defaultMappingOptions = new MappingOperationOptions(_serviceCtor);
 }
Exemplo n.º 19
0
 public ResolutionContext(object source, object destination, TypePair types, MappingOperationOptions options, IRuntimeMapper mapper)
 {
     SourceValue = source;
     DestinationValue = destination;
     Options = options;
     Mapper = mapper;
     Types = types;
 }