예제 #1
0
            // The Typed method for RawAutoMappers
            static IAutoMapperRequestKey <TSource, TDestination> SubmitRawAutoMapperRequest <TSource, TDestination>
            (
                IAutoMapperConfigDetails autoMapperConfigDetails,
                Type sourceType,
                Type destinationType,
                string configPackageName,
                IHaveAMapperConfigurationStep configStarterForThisRequest,
                IAutoMapperService autoMapperProvider
            )
            {
                IMapTypeDefinition srcMapTypeDef = new MapTypeDefinition(typeof(TSource));
                IMapTypeDefinition dstMapTypeDef = new MapTypeDefinition(typeof(TDestination));

                IAutoMapperRequestKey <TSource, TDestination> result
                    = autoMapperProvider.SubmitRawAutoMapperRequest <TSource, TDestination>
                      (
                          srcMapTypeDef: srcMapTypeDef,
                          dstMapTypeDef: dstMapTypeDef,
                          configuationDetails: autoMapperConfigDetails,
                          configPackageName: configPackageName,
                          configStarterForThisRequest: configStarterForThisRequest
                      );

                return(result);
            }
예제 #2
0
 // Typed Get Mapper (Simple wrapper around our pass through method.)
 public IMapper GetRawAutoMapper <TSource, TDestination>
 (
     IAutoMapperRequestKey <TSource, TDestination> autoMapperRequestKey
 )
 {
     return(_autoMapperCache.GetAutoMapper(autoMapperRequestKey));
 }
예제 #3
0
        // Create a new AutoMapper (IMapper)
        public IMapper BuildAutoMapper(IAutoMapperRequestKey <TSource, TDestination> mapperRequestKey)
        {
            CheckTypeToCreate("source", typeof(TSource), mapperRequestKey.SourceTypeDef.TargetType);
            CheckTypeToCreate("destination", typeof(TDestination), mapperRequestKey.DestinationTypeDef.TargetType);

            IConfigurationProvider configProvider = _mapperConfigurationBuilder.GetNewConfiguration(mapperRequestKey);

            IMapper result = configProvider.CreateMapper();

            return(result);
        }
예제 #4
0
        private IMapper BuildAutoMapperGen(IAutoMapperRequestKeyGen mapRequestGen)
        {
            IAutoMapperRequestKey <TSource, TDestination> mapRequestTyped
                = mapRequestGen as IAutoMapperRequestKey <TSource, TDestination>;

            if (mapRequestTyped == null)
            {
                throw new InvalidOperationException($"{nameof(mapRequestGen)} does not implement the correct typed {nameof(IAutoMapperRequestKey<TSource, TDestination>)} interface.");
            }

            return(BuildAutoMapper(mapRequestTyped));
        }
예제 #5
0
        // Typed Submit with Mapping Configuration.
        public IPropBagMapperRequestKey <TSource, TDestination> SubmitPropBagMapperRequest <TSource, TDestination>
        (
            PropModelType propModel,
            IConfigureAMapper <TSource, TDestination> mappingConfiguration,
            IHaveAMapperConfigurationStep configStarterForThisRequest,
            IPropFactory propFactory = null
        )
            where TDestination : class, IPropBag
        {
            // Use the AutoMapperService to register a 'raw' request.
            IAutoMapperRequestKey <TSource, TDestination> autoMapperRequestKey =
                this.SubmitRawAutoMapperRequest <TSource, TDestination>
                (
                    propModel,
                    mappingConfiguration,
                    configStarterForThisRequest
                );


            // Note: at this point we can fetch the Mapper Config Details.
            //IAutoMapperConfigDetails autoMapperConfigDetails = autoMapperRequestKey.AutoMapperConfigDetails;
            //IPropBagMapperConfigDetails propBagMapperConfigDetails = (IPropBagMapperConfigDetails)autoMapperConfigDetails;


            // Create a MapperBuilder for this request.
            IPropBagMapperBuilder <TSource, TDestination> propBagMapperBuilder
                = BuildTheAutoMapperBuilder <TSource, TDestination>(/*configStarterForThisRequest*/);

            // Create the PropBag Mapper Request.
            IPropBagMapperRequestKey <TSource, TDestination> propBagMapperRequestKey
                = new PropBagMapperRequestKey <TSource, TDestination>
                  (
                      propBagMapperBuilder,
                      autoMapperRequestKey // This contains a reference to the propModel.
                      //,
                      //propModel
                  );


            // Note: at this point we can fetch the Mapper Config Details from the PropBagMapperRequestKey.
            //IPropBagMapperConfigDetails propBagMapperConfigDetails = propBagMapperRequestKey.PropBagMapperConfigDetails;


            //// Store the request
            //IPropBagMapperKeyGen newMapRequest = RegisterPropBagMapperRequest(typedMapperRequest);
            //return (IPropBagMapperKey<TSource, TDestination>)newMapRequest;

            // We could store the request in the PropBagMapper Cache, but it would not be used.
            return(propBagMapperRequestKey);
        }
예제 #6
0
 public bool Equals(IAutoMapperRequestKey <TSource, TDestination> other)
 {
     if (other == null)
     {
         return(false);
     }
     if ((this.DestinationTypeDef.Equals(other.DestinationTypeDef)) && this.SourceTypeDef.Equals(other.SourceTypeDef))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
예제 #7
0
        public void BuildEmitProxyConfig(IAutoMapperRequestKey <TSource, TDestination> mapRequest, IMapperConfigurationExpression cfg)
        {
            Func <TDestination, TSource> regularInstanceCreator = mapRequest.MappingConfiguration.SourceConstructor;

            Type newWrapperType = mapRequest.DestinationTypeDef.RunTimeType;

            cfg.CreateMap(typeof(TSource), newWrapperType);

            if (regularInstanceCreator != null)
            {
                cfg.CreateMap(newWrapperType, typeof(TSource)); //.ConstructUsing(RegularInstanceCreator);
            }
            else
            {
                cfg.CreateMap(newWrapperType, typeof(TSource));
            }
        }
예제 #8
0
        // From AutoMapperRequestKey (Typed)
        private IMapper GetRawAutoMapper <TSource, TDestination>
        (
            IAutoMapperRequestKey <TSource, TDestination> rawAutoMappeRequestKey
        )
            where TDestination : class, IPropBag
        {
            //if (rawAutoMappeRequestKey.AutoMapper == null)
            //{
            //    IMapper autoMapper = _autoMapperService.GetRawAutoMapper<TSource, TDestination>(rawAutoMappeRequestKey);
            //    rawAutoMappeRequestKey.AutoMapper = autoMapper;
            //}

            //return rawAutoMappeRequestKey.AutoMapper;

            IMapper result = _autoMapperService.GetRawAutoMapper <TSource, TDestination>(rawAutoMappeRequestKey);

            return(result);
        }
예제 #9
0
        public PropBagMapperRequestKey
        (
            IPropBagMapperBuilder <TSource, TDestination> propBagMapperBuilder,
            IAutoMapperRequestKey <TSource, TDestination> autoMapperRequestKey
            //,
            //PropModelType propModel
        )
            : base
            (
                propBagMapperBuilder.PropBagMapperBuilderGen,
                autoMapperRequestKey
                //  ,
                //propModel
            )
        {
            _propBagMapperBuilder = propBagMapperBuilder;

            CheckTypes();
        }
예제 #10
0
        public void BuildExtraMemberConfig(IAutoMapperRequestKey <TSource, TDestination> mapRequest, IMapperConfigurationExpression cfg)
        {
            //PropModelType propModel = mapRequest.DestinationTypeDef.UniqueRef as PropModelType;

            if (mapRequest.AutoMapperConfigDetails.ExtensionSourceId != SimplePropBagMapperService.PROP_BAG_MAPPER_CONFIG_DETAIL_EXTENSION_SOURCE_ID)
            {
                throw new InvalidOperationException("The ExtraMembersConfigFinalStep can only be used with a PropBagMapper.");
            }

            IPropBagMapperConfigDetails propBagMapperConfigDetails = mapRequest.AutoMapperConfigDetails as IPropBagMapperConfigDetails;

            if (propBagMapperConfigDetails == null)
            {
                throw new InvalidOperationException("The PropBagMapperConfigDetails is null.");
            }

            PropModelType propModel = propBagMapperConfigDetails.PropModel;


            // TODO: Create an interface for the ExtraMembersProvider and then create
            // property so that this value can be set after construction, but before calling BuildExtraMemberConfig.
            IEnumerable <MemberInfo> extraMembers = new ExtraMembersProvider().GetExtraMembers(propModel);

            Func <TDestination, TSource> regularInstanceCreator = mapRequest.MappingConfiguration.SourceConstructor;

            //cfg.IncludeExtraMembersForType(typeof(Destination), extraMembers);

            cfg
            .CreateMap <TSource, TDestination>()
            //.RegisterExtraMembers(cfg)
            .AddExtraDestintionMembers(extraMembers)
            //.ForMember("Item1", opt => opt.Condition(srcA => srcA.Item1 != "AA"))
            ;

            //Func<Destination, bool> cond = (s => "x" != (string)s.GetIt("Item1", typeof(string)));

            cfg
            .CreateMap <TDestination, TSource>()
            .AddExtraSourceMembers(extraMembers)
            //.ForMember("Item1", opt => opt.Condition(cond))
            ;
        }
예제 #11
0
        private IConfigurationProvider GetNewConfiguration_Internal
        (
            Action <IMapperConfigurationExpression> compositeGenAction,
            //Action<IPropBagMapperKey<TSource, TDestination>,
            //IMapperConfigurationExpression> finalAction,
            //IPropBagMapperKey<TSource, TDestination> mapRequest
            IAutoMapperRequestKey <TSource, TDestination> mapRequest
        )
        {
            // Wrap up the mapRequestValue in a standard Action<IMapperConfigurationExpression> action.
            Action <IMapperConfigurationExpression> wrappedAction = GetWrappedAction
                                                                    (
                //finalAction,
                mapRequest
                                                                    );

            compositeGenAction += wrappedAction;

            IConfigurationProvider result = new MapperConfiguration(compositeGenAction);

            return(result);
        }
예제 #12
0
        // TODO: Figure out a way to avoid wrapping the mapRequest in the new action.
        // can we have the caller provide this when making the call?
        private Action <IMapperConfigurationExpression> GetWrappedAction
        (
            //Action<IPropBagMapperKey<TSource, TDestination>,
            //IMapperConfigurationExpression> finalAction,
            //IPropBagMapperKey<TSource, TDestination> mapRequest
            IAutoMapperRequestKey <TSource, TDestination> mapRequest
        )
        {
            return(OurAction);

            // Nested Method, wraps the mapRequest value for use later, when this
            // action is called.
            void OurAction(IMapperConfigurationExpression exp)
            {
                //Action<IPropBagMapperKey<TSource, TDestination>, IMapperConfigurationExpression> finalAction
                //    = mapRequest.MappingConfiguration.FinalConfigActionProvider.ActionStep;

                Action <IAutoMapperRequestKey <TSource, TDestination>, IMapperConfigurationExpression> finalAction
                    = mapRequest.MappingConfiguration.FinalConfigActionProvider.ActionStep;

                finalAction(mapRequest, exp);
            }
        }
예제 #13
0
        // Submit a request to queue up the creation of a Raw AutoMapper, and receive the RequestKey.
        private IAutoMapperRequestKey <TSource, TDestination> SubmitRawAutoMapperRequest <TSource, TDestination>
        (
            PropModelType propModel,
            IConfigureAMapper <TSource, TDestination> mappingConfiguration,
            IHaveAMapperConfigurationStep configStarterForThisRequest
        )
            where TDestination : class, IPropBag
        {
            IMapTypeDefinition srcMapTypeDef
                = _mapTypeDefinitionProvider.GetTypeDescription(typeof(TSource), uniqueRef: propModel, uniqueToken: null);

            IMapTypeDefinition dstMapTypeDef
                = _mapTypeDefinitionProvider.GetTypeDescription(typeof(TDestination), uniqueRef: propModel, uniqueToken: null);

            CheckRunTimeType(propModel, typeof(TDestination));

            IAutoMapperConfigDetails pbMapperConfigDetails
                = new PropBagMapperConfigDetails
                  (
                      PROP_BAG_MAPPER_CONFIG_DETAIL_EXTENSION_SOURCE_ID,
                      mappingConfiguration.PackageName,
                      propModel
                  );

            IAutoMapperRequestKey <TSource, TDestination> autoMapperRequestKey
                = _autoMapperService.SubmitRawAutoMapperRequest <TSource, TDestination>
                  (
                      srcMapTypeDef,
                      dstMapTypeDef,
                      pbMapperConfigDetails,
                      mappingConfiguration,
                      configStarterForThisRequest
                  );

            return(autoMapperRequestKey);
        }