Пример #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);
        }
Пример #2
0
 public ResolutionContext(object source, object destination, TypePair types, MappingOperationOptions options, IRuntimeMapper mapper)
 {
     SourceValue      = source;
     DestinationValue = destination;
     Options          = options;
     Mapper           = mapper;
     Types            = types;
 }
Пример #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));
        }
Пример #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;
 }
Пример #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));
        }
Пример #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));
        }
Пример #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;
 }
Пример #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));
        }
Пример #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);
        }
Пример #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));
        }
Пример #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);
        }
Пример #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));
        }
Пример #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));
        }
Пример #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;
 }
Пример #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);
        }
Пример #16
0
 public ResolutionContext(TypeMap typeMap, object source, Type sourceType, Type destinationType, MappingOperationOptions options)
     : this(typeMap, source, null, sourceType, destinationType, options)
 {
 }
Пример #17
0
 public ResolutionContext(MappingOperationOptions options, IRuntimeMapper mapper)
 {
     Options = options;
     Mapper  = mapper;
 }
Пример #18
0
 public Mapper(IConfigurationProvider configurationProvider, Func <Type, object> serviceCtor)
 {
     _configurationProvider = configurationProvider;
     _serviceCtor           = serviceCtor;
     _defaultMappingOptions = new MappingOperationOptions(_serviceCtor);
 }
Пример #19
0
 public ResolutionContext(object source, object destination, TypePair types, MappingOperationOptions options, IRuntimeMapper mapper)
 {
     SourceValue = source;
     DestinationValue = destination;
     Options = options;
     Mapper = mapper;
     Types = types;
 }