コード例 #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
        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);
        }
コード例 #3
0
ファイル: Mapper.cs プロジェクト: zwq000/AutoMapper
        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>(ServiceCtor);

            opts(typedOptions);

            typedOptions.BeforeMapAction(source, destination);

            var context = new ResolutionContext(typedOptions, this);

            destination = MapCore(source, destination, context, sourceType, destinationType);

            typedOptions.AfterMapAction(source, destination);

            return(destination);
        }
コード例 #4
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);

            options.BeforeMapAction(source, null);

            var context = new ResolutionContext(options, this);

            var destination = func(source, null, context);

            options.AfterMapAction(source, destination);

            return(destination);
        }
コード例 #5
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);

            typedOptions.BeforeMapAction(source, destination);

            var context = new ResolutionContext(typedOptions, this);

            destination = func(source, destination, context);

            typedOptions.AfterMapAction(source, destination);

            return(destination);
        }