protected override Expression GetEnumerablePopulation( EnumerablePopulationBuilder builder, IObjectMappingData mappingData) { if (builder.ElementTypesAreSimple) { builder.AssignSourceVariableFrom(s => s.SourceItemsProjectedToTargetType().ExcludingTargetItems()); builder.AssignTargetVariable(); builder.AddNewItemsToTargetVariable(mappingData); return(builder); } if (builder.ElementsAreIdentifiable) { builder.CreateCollectionData(); builder.MapIntersection(mappingData); builder.AssignSourceVariableFrom(s => s.CollectionDataNewSourceItems()); builder.AssignTargetVariable(); builder.AddNewItemsToTargetVariable(mappingData); return(builder); } builder.AssignSourceVariableFromSourceObject(); builder.AssignTargetVariable(); builder.AddNewItemsToTargetVariable(mappingData); return(builder); }
protected override Expression GetEnumerablePopulation( EnumerablePopulationBuilder builder, IObjectMappingData mappingData) { builder.AssignSourceVariableFromSourceObject(); builder.AssignTargetVariable(); builder.AddNewItemsToTargetVariable(mappingData); return(builder); }
private ObjectMapperData( IObjectMappingData mappingData, IQualifiedMember sourceMember, QualifiedMember targetMember, int?dataSourceIndex, ObjectMapperData declaredTypeMapperData, ObjectMapperData parent, bool isForStandaloneMapping) : base( mappingData.MappingContext.RuleSet, sourceMember.Type, targetMember.Type, targetMember, parent) { MapperContext = mappingData.MappingContext.MapperContext; DeclaredTypeMapperData = declaredTypeMapperData; _childMapperDatas = new List <ObjectMapperData>(); DataSourceIndex = dataSourceIndex.GetValueOrDefault(); MappingDataObject = GetMappingDataObject(parent); SourceMember = sourceMember; var mappingDataType = typeof(IMappingData <,>).MakeGenericType(SourceType, TargetType); SourceObject = GetMappingDataProperty(mappingDataType, "Source"); TargetObject = Expression.Property(MappingDataObject, "Target"); CreatedObject = Expression.Property(MappingDataObject, "CreatedObject"); var isPartOfDerivedTypeMapping = declaredTypeMapperData != null; if (isPartOfDerivedTypeMapping) { EnumerableIndex = declaredTypeMapperData.EnumerableIndex; ParentObject = declaredTypeMapperData.ParentObject; } else { EnumerableIndex = GetMappingDataProperty(mappingDataType, "EnumerableIndex"); ParentObject = Expression.Property(MappingDataObject, "Parent"); } NestedAccessFinder = new NestedAccessFinder(MappingDataObject); _mapChildMethod = GetMapMethod(MappingDataObject.Type, 4); _mapElementMethod = GetMapMethod(MappingDataObject.Type, 3); _dataSourcesByTargetMemberName = new Dictionary <string, DataSourceSet>(); DataSourcesByTargetMember = new Dictionary <QualifiedMember, DataSourceSet>(); if (targetMember.IsEnumerable) { EnumerablePopulationBuilder = new EnumerablePopulationBuilder(this); } else { TargetTypeHasNotYetBeenMapped = IsTargetTypeFirstMapping(parent); TargetTypeWillNotBeMappedAgain = IsTargetTypeLastMapping(); _instanceVariable = Expression .Variable(TargetType, TargetType.GetVariableNameInCamelCase()); } ReturnLabelTarget = Expression.Label(TargetType, "Return"); if (isForStandaloneMapping) { RequiredMapperFuncsByKey = new Dictionary <ObjectMapperKeyBase, LambdaExpression>(); } if (IsRoot) { Context = new MapperDataContext(this, isForStandaloneMapping, isPartOfDerivedTypeMapping); return; } Context = new MapperDataContext( this, isForStandaloneMapping, isPartOfDerivedTypeMapping || parent.Context.IsForDerivedType); parent._childMapperDatas.Add(this); Parent = parent; }
private ObjectMapperData( IObjectMappingData mappingData, IQualifiedMember sourceMember, QualifiedMember targetMember, int?dataSourceIndex, ObjectMapperData declaredTypeMapperData, ObjectMapperData parent, bool isForStandaloneMapping) : base( mappingData.MappingContext.RuleSet, sourceMember.Type, targetMember.Type, sourceMember, targetMember, parent) { MapperContext = mappingData.MappingContext.MapperContext; DeclaredTypeMapperData = OriginalMapperData = declaredTypeMapperData; _childMapperDatas = new List <ObjectMapperData>(); DataSourceIndex = dataSourceIndex.GetValueOrDefault(); MappingDataObject = GetMappingDataObject(parent); SourceMember = sourceMember; var mappingDataType = typeof(IMappingData <,>).MakeGenericType(SourceType, TargetType); SourceObject = GetMappingDataProperty(mappingDataType, RootSourceMemberName); TargetObject = GetMappingDataProperty(RootTargetMemberName); CreatedObject = GetMappingDataProperty(nameof(CreatedObject)); var isPartOfDerivedTypeMapping = declaredTypeMapperData != null; if (isPartOfDerivedTypeMapping) { EnumerableIndex = declaredTypeMapperData.EnumerableIndex; ParentObject = declaredTypeMapperData.ParentObject; } else { EnumerableIndex = GetMappingDataProperty(mappingDataType, nameof(EnumerableIndex)); ParentObject = GetMappingDataProperty(nameof(Parent)); } ExpressionInfoFinder = new ExpressionInfoFinder(MappingDataObject); DataSourcesByTargetMember = new Dictionary <QualifiedMember, DataSourceSet>(); ReturnLabelTarget = Expression.Label(TargetType, "Return"); _mappedObjectCachingMode = MapperContext.UserConfigurations.CacheMappedObjects(this); if (targetMember.IsEnumerable) { EnumerablePopulationBuilder = new EnumerablePopulationBuilder(this); } if (IsRoot) { TargetTypeHasNotYetBeenMapped = true; TargetTypeWillNotBeMappedAgain = IsTargetTypeLastMapping(parent); Context = new MapperDataContext(this, true, isPartOfDerivedTypeMapping); return; } parent._childMapperDatas.Add(this); Parent = parent; if (!this.TargetMemberIsEnumerableElement()) { TargetTypeHasNotYetBeenMapped = IsTargetTypeFirstMapping(parent); TargetTypeWillNotBeMappedAgain = IsTargetTypeLastMapping(parent); } Context = new MapperDataContext( this, isForStandaloneMapping, isPartOfDerivedTypeMapping || parent.Context.IsForDerivedType); }
internal SourceItemsSelector(EnumerablePopulationBuilder builder) { _builder = builder; }
protected abstract Expression GetEnumerablePopulation( EnumerablePopulationBuilder builder, IObjectMappingData mappingData);
private ObjectMapperData( IMappingContext mappingContext, IQualifiedMember sourceMember, QualifiedMember targetMember, int?dataSourceIndex, ObjectMapperData declaredTypeMapperData, ObjectMapperData parent, bool isForStandaloneMapping) : base( mappingContext.RuleSet, sourceMember, targetMember, parent, mappingContext.MapperContext) { DataSourceIndex = dataSourceIndex.GetValueOrDefault(); CreatedObject = GetMappingDataProperty(nameof(CreatedObject)); var isPartOfDerivedTypeMapping = declaredTypeMapperData != null; if (isPartOfDerivedTypeMapping) { DeclaredTypeMapperData = OriginalMapperData = declaredTypeMapperData; ElementIndex = declaredTypeMapperData.ElementIndex; ElementKey = declaredTypeMapperData.ElementKey; ParentObject = declaredTypeMapperData.ParentObject; declaredTypeMapperData.DerivedMapperDatas.Add(this); } else { ElementIndex = GetElementIndexAccess(); ElementKey = GetElementKeyAccess(); ParentObject = GetParentObjectAccess(); } _returnLabelTarget = Expression.Label(TargetType, "Return"); _mappedObjectCachingMode = MapperContext.UserConfigurations.CacheMappedObjects(this); if (targetMember.IsEnumerable) { EnumerablePopulationBuilder = new EnumerablePopulationBuilder(this); } if (IsRoot) { TargetTypeWillNotBeMappedAgain = IsTargetTypeLastMapping(parent); Context = new MapperDataContext(this, true, isPartOfDerivedTypeMapping); return; } parent.ChildMapperDatas.Add(this); if (this.TargetMemberIsEnumerableElement()) { TargetTypeHasBeenMappedBefore = true; } else { TargetTypeHasBeenMappedBefore = IsNotTargetTypeFirstMapping(parent); TargetTypeWillNotBeMappedAgain = IsTargetTypeLastMapping(parent); } Context = new MapperDataContext( this, isForStandaloneMapping, isPartOfDerivedTypeMapping || parent.Context.IsForDerivedType); }