public static Expression GetMappingOrNull( MappingCreationContext context, out bool isConditional) { var mappingData = context.MappingData; var derivedTypeDataSources = DerivedComplexTypeDataSourcesFactory.CreateFor(mappingData); if (derivedTypeDataSources.None()) { isConditional = false; return(null); } var derivedTypeDataSourceSet = DataSourceSet.For( derivedTypeDataSources, mappingData, ValueExpressionBuilders.ValueSequence); isConditional = derivedTypeDataSources.Last().IsConditional&& !mappingData.MapperData.TargetType.IsAbstract(); if (!isConditional) { context.MappingComplete = true; } return(derivedTypeDataSourceSet.BuildValue()); }
public static IDataSourceSet CreateFor(DataSourceFindContext findContext) { var validDataSources = EnumerateDataSources(findContext).ToArray(); return(DataSourceSet.For( validDataSources, findContext, ValueExpressionBuilders.ValueTree)); }
public static IDataSourceSet CreateFor(IObjectMappingData rootMappingData) { var rootDataSourceFactory = _mappingRootDataSourceFactories .First(rootMappingData, (rmd, mef) => mef.IsFor(rmd)); var rootDataSource = rootDataSourceFactory.CreateFor(rootMappingData); return(DataSourceSet.For(rootDataSource, rootMappingData.MapperData)); }
private static IDataSourceSet CreateNullDataSourceSet( IMemberMapperData mapperData, Func <QualifiedMember, string> commentFactory) { return(DataSourceSet.For( new NullDataSource( ReadableExpression.Comment(commentFactory.Invoke(mapperData.TargetMember))), mapperData)); }
private static IDataSource GetMapFromConditionOrDefaultDataSource( IObjectMappingData declaredTypeMappingData, Expression condition, DerivedSourceTypeCheck derivedSourceCheck, IEnumerable <TypePairGroup> typePairGroups, Type targetType) { var declaredTypeMapperData = declaredTypeMappingData.MapperData; var typePairDataSources = new List <IDataSource>(); Expression derivedTypeMapping; IObjectMappingData derivedTypeMappingData; foreach (var typePairGroup in typePairGroups) { var typePairsCondition = declaredTypeMapperData.GetTypePairsCondition(typePairGroup.TypePairs) ?? declaredTypeMapperData.GetTargetValidCheckOrNull(typePairGroup.DerivedTargetType); derivedTypeMapping = GetReturnMappingResultExpression( declaredTypeMappingData, derivedSourceCheck.TypedVariable, typePairGroup.DerivedTargetType, out derivedTypeMappingData); var typePairDataSource = new DerivedComplexTypeDataSource( derivedTypeMappingData.MapperData.SourceMember, typePairsCondition, derivedTypeMapping); typePairDataSources.Add(typePairDataSource); } var derivedTargetTypeDataSources = DataSourceSet.For( typePairDataSources, declaredTypeMapperData, ValueExpressionBuilders.ValueSequence); derivedTypeMapping = GetReturnMappingResultExpression( declaredTypeMappingData, derivedSourceCheck.TypedVariable, targetType, out derivedTypeMappingData); var derivedTypeMappings = Block( derivedTargetTypeDataSources.BuildValue(), derivedTypeMapping); return(new DerivedComplexTypeDataSource( derivedTypeMappingData.MapperData.SourceMember, derivedSourceCheck, condition, derivedTypeMappings, declaredTypeMapperData)); }
public static IMemberPopulator NoDataSources(MemberPopulationContext context) { var noDataSourcesMessage = CreateNullPopulatorDescription( GetNoDataSourcesMessage, context.MemberMapperData); var noDataSource = new NullDataSource(noDataSourcesMessage); var noDataSources = DataSourceSet.For(noDataSource, context); context.MemberMapperData.RegisterTargetMemberDataSources(noDataSources); return(CreateNullMemberPopulator(noDataSourcesMessage, context, (msg, md) => msg)); }
private Expression GetPopulation( Expression elementMapping, QualifiedMember dictionaryEntryMember, IObjectMappingData mappingData) { var elementMapperData = new ChildMemberMapperData(dictionaryEntryMember, MapperData); var sourceMember = mappingData.MapperData.SourceMember; var mappingDataSource = new AdHocDataSource(sourceMember, elementMapping); var dataSourceSetInfo = new SimpleDataSourceSetInfo(mappingData.MappingContext, elementMapperData); var mappingDataSources = DataSourceSet.For(mappingDataSource, dataSourceSetInfo); var populator = new MemberPopulator(mappingDataSources, elementMapperData); var populationExpression = populator.GetPopulation(); return(populationExpression); }
private Expression GetPopulation( Expression elementMapping, QualifiedMember dictionaryEntryMember, IObjectMappingData mappingData) { var elementMapperData = new ChildMemberMapperData(dictionaryEntryMember, MapperData); var sourceMember = mappingData.MapperData.SourceMember; var mappingDataSource = new AdHocDataSource(sourceMember, elementMapping); var mappingDataSources = DataSourceSet.For(mappingDataSource, elementMapperData); var populationExpression = MemberPopulator .WithoutRegistration(mappingDataSources) .GetPopulation(); return(populationExpression); }
protected override bool ShortCircuitMapping(MappingCreationContext context, out Expression mapping) { var derivedTypeDataSources = DerivedComplexTypeDataSourcesFactory.CreateFor(context.MappingData); if (derivedTypeDataSources.None()) { return(base.ShortCircuitMapping(context, out mapping)); } var derivedTypeDataSourceSet = DataSourceSet.For( derivedTypeDataSources, context.MapperData, ValueExpressionBuilders.ValueSequence); mapping = derivedTypeDataSourceSet.BuildValue(); if (derivedTypeDataSources.Last().IsConditional) { context.MappingExpressions.Add(mapping); return(false); } var shortCircuitReturns = GetShortCircuitReturns(context.MappingData).ToArray(); if (shortCircuitReturns.Any()) { context.MappingExpressions.AddRange(shortCircuitReturns); } if (mapping.NodeType == ExpressionType.Goto) { mapping = ((GotoExpression)mapping).Value; context.MappingExpressions.Add(context.MapperData.GetReturnLabel(mapping)); } else { context.MappingExpressions.Add(mapping); context.MappingExpressions.Add(context.MapperData.GetReturnLabel(mapping.Type.ToDefaultExpression())); } mapping = Expression.Block(context.MappingExpressions); return(true); }
public void UpdateFrom(MappingCreationContext toTargetContext, IDataSource toTargetDataSource) { var toTargetMappingData = toTargetContext.MappingData; MappingData.MapperKey.AddSourceMemberTypeTesterIfRequired(toTargetMappingData); if (!MapperData.IsRoot) { var dataSourceSet = DataSourceSet.For(toTargetDataSource, toTargetMappingData); MapperData.RegisterTargetMemberDataSources(dataSourceSet); } if (TargetMember.IsComplex) { UpdateChildMemberDataSources(toTargetContext.MapperData); return; } UpdateEnumerableVariablesIfAppropriate(toTargetContext.MapperData, MapperData); }
private static Expression GetMappingOrNull( IObjectMappingData mappingData, out bool isConditional) { var mappingFactoryDataSources = GetMappingFactoryDataSources(mappingData.MapperData); if (mappingFactoryDataSources.None()) { isConditional = false; return(null); } var mappingFactories = DataSourceSet.For( mappingFactoryDataSources, mappingData, ValueExpressionBuilders.ValueSequence); isConditional = mappingFactoryDataSources.Last().IsConditional; return(mappingFactories.BuildValue()); }
public static IDataSourceSet CreateFor(DataSourceFindContext findContext) { var validDataSources = EnumerateDataSources(findContext).ToArray(); return(DataSourceSet.For(validDataSources, findContext.MemberMapperData)); }