/// <summary> /// Merges another <see cref="MapperContext"/> with this instance of <see cref="MapperContext"/>. /// </summary> /// <remarks> /// This will modify current object. /// </remarks> /// <param name="mapperContext"></param> /// <param name="mergeBehavior"></param> /// <exception cref="InvalidOperationException"></exception> /// <exception cref="ArgumentOutOfRangeException"></exception> public void MergeWith(MapperContext mapperContext, MapperContextMergeBehavior mergeBehavior = MapperContextMergeBehavior.ThrowException) { switch (mergeBehavior) { case MapperContextMergeBehavior.OverwriteDuplicates: { Lock.EnterWriteLock(); try { foreach (var row in mapperContext.MappingRows) { MappingRows[row.Key] = row.Value; } } finally { Lock.ExitWriteLock(); } break; } case MapperContextMergeBehavior.SkipDuplicates: { Lock.EnterWriteLock(); try { foreach (var row in mapperContext.MappingRows) { if (!MappingRows.ContainsKey(row.Key)) { MappingRows[row.Key] = row.Value; } } } finally { Lock.ExitWriteLock(); } break; } case MapperContextMergeBehavior.ThrowException: { Lock.EnterReadLock(); try { foreach (var row in mapperContext.MappingRows) { if (MappingRows.ContainsKey(row.Key)) { throw new InvalidOperationException(); } } } finally { Lock.ExitReadLock(); } break; } default: throw new ArgumentOutOfRangeException(nameof(mergeBehavior), mergeBehavior, null); } }
/// <summary> /// Creates a new instance of <see cref="MapperScope"/> using given parent and context. /// </summary> /// <param name="parentScope">The parent scope.</param> /// <param name="context">The context to use in this scope.</param> public MapperScope(MapperScope parentScope, MapperContext context) { Context = context ?? throw new ArgumentNullException(nameof(context)); ParentScope = parentScope; }
/// <summary> /// Creates a new instance of <see cref="MapperScope"/> using an empty context. /// </summary> public MapperScope() { Context = new MapperContext(); }
private static Expression CreateClassMapping(MapperContext context, Type destinationClassType, Type sourceClassType) { return(null); }
private static Expression DestinationFromValueResolver(MapperContext context, Expression destination, Expression source, Mapping.MemberMapInfo memberMapInfo) { return(null); }
public static MappingCompiledInfo CompileMapping( Mapper mapper, MapperContext context, MappingCompiledInfo compiledInfo, Mapping mapping, MappingType mappingType) { _ensureCompilers(); var compilerContext = new Context(mapper, context, mapping, compiledInfo); var source = Expression.Parameter(mapping.SourceType, "source"); switch (mappingType) { case MappingType.ObjectMap: { if (compiledInfo.ObjectMapExpression != null) { return(compiledInfo); } break; } case MappingType.QueryableProjection: { if (compiledInfo.ProjectionExpression != null) { return(compiledInfo); } foreach (var compiler in Compilers) { if (compiler.CanMap(compilerContext, mapping.SourceType, mapping.DestinationType)) { var exp = compiler.CreateConvertExpression( compilerContext, source, mapping.DestinationType, mappingType ); compiledInfo.ProjectionExpression = Expression.Lambda(exp, source); } } break; } case MappingType.CollectionSynchronization: { break; } default: throw new ArgumentOutOfRangeException(nameof(mappingType), mappingType, null); } return(compiledInfo); }