Exemplo n.º 1
0
        public ObjectMapper <TSource, TTarget> Create <TSource, TTarget>(ObjectMappingData <TSource, TTarget> mappingData)
        {
            var mappingExpression = DataSourceSetFactory.CreateFor(mappingData).BuildValue();

            if (mappingExpression == Constants.EmptyExpression)
            {
                return(null);
            }

            mappingExpression = MappingFactory
                                .UseLocalSourceValueVariableIfAppropriate(mappingExpression, mappingData.MapperData);

            var mappingLambda = Expression.Lambda <MapperFunc <TSource, TTarget> >(
                mappingExpression,
                mappingData.MapperData.MappingDataObject);

            var mapper = new ObjectMapper <TSource, TTarget>(mappingLambda, mappingData);

            if (_creationCallbacksByKey == null)
            {
                return(mapper);
            }

            var creationCallbackKey = new MapperCreationCallbackKey(mappingData.MapperData);

            if (_creationCallbacksByKey.TryGetValue(creationCallbackKey, out var creationCallback))
            {
                creationCallback.Invoke(mapper);
            }

            return(mapper);
        }
            private static IDataSourceSet[] GetArgumentDataSources(TInvokable invokable, ConstructionKey key)
            {
                return(invokable
                       .GetParameters()
                       .ProjectToArray(key.MappingData, (mappingData, p) =>
                {
                    var parameterMapperData = new ChildMemberMapperData(
                        mappingData.MapperData.TargetMember.Append(Member.ConstructorParameter(p)),
                        mappingData.MapperData);

                    var memberMappingData = mappingData.GetChildMappingData(parameterMapperData);
                    var dataSources = DataSourceSetFactory.CreateFor(new DataSourceFindContext(memberMappingData));

                    return dataSources;
                }));
            }
Exemplo n.º 3
0
        private static IMemberPopulator Create(MemberPopulationContext context)
        {
            if (TargetMemberIsUnmappable(context, out var reason))
            {
                return(MemberPopulator.Unmappable(context, reason));
            }

            if (context.TargetMemberIsUnconditionallyIgnored(out var populateCondition))
            {
                return(MemberPopulator.IgnoredMember(context));
            }

            var dataSourceFindContext = context.GetDataSourceFindContext();
            var dataSources           = DataSourceSetFactory.CreateFor(dataSourceFindContext);

            if (dataSources.None)
            {
                return(MemberPopulator.NoDataSource(context));
            }

            return(MemberPopulator.WithRegistration(dataSources, populateCondition));
        }