public void ConvertUsing(Type from, Type to, Func <object, object, TContext, object> convert) { AssertIsNotInitialized(); AssertNoExistingMaps(from, to); MapperAction <TContext> mapperAction = (ofrom, oto, context) => convert(ofrom, oto, context); _mapCache.Add(from, to, mapperAction); SetMapper(from, to, mapperAction); if (_diagnosticsEnabled) { _mapCreationInfo.Add(new MapInfoEntry(mapperAction)); } }
public void ConvertUsing <TFrom, TTo>(Func <TFrom, TTo, TContext, TTo> convert) { AssertIsNotInitialized(); AssertNoExistingMaps(typeof(TFrom), typeof(TTo)); MapperAction <TContext> mapperAction = (from, to, context) => convert((TFrom)from, (TTo)to, context); _mapCache.Add(typeof(TFrom), typeof(TTo), mapperAction); SetMapper(typeof(TFrom), typeof(TTo), mapperAction); if (_diagnosticsEnabled) { _mapCreationInfo.Add(new MapInfoEntry(mapperAction)); } }
public void Initialize() { if (!Initialized) { var mappingCollection = new MappingCollection <TFrom, TTo, TContext>(_mapper); foreach (var @override in _override) { @override(mappingCollection); } _override.Clear(); mappingCollection.DoAutomapping(); mappingCollection.VerifyMap(); _mapStatement = _mapper.Builder.BuildAction(mappingCollection); Initialized = true; } }
public IMappingCollection <TFrom, TTo, TContext> SetMember(MemberInfo to, MapperAction <TContext> getter) { return(SetMember(new[] { to }, getter)); }
public IMappingCollection <TFrom, TTo, TContext> SetMember(MemberInfo[] member, MapperAction <TContext> getter) { if (member == null) { throw new ArgumentNullException("member"); } if (!member.Last().IsWritable()) { throw new ArgumentException(string.Format("Target member {0} must be writeable", member)); } var setter = MapEntry(member); setter.DestinationType = member.Last().ReturnType(); setter.Remap = false; setter.SourceObjectType = MemberEntryType.Function; setter.SourceFunc = getter; setter.SourceType = null; return(this); }
private void SetMapper(Type from, Type to, MapperAction <TContext> action) { GetType().GetMethod("InternalSetMapper", BindingFlags.Default | BindingFlags.NonPublic | BindingFlags.Instance) .MakeGenericMethod(from, to) .Invoke(this, new[] { action }); }
private void InternalSetMapper <TFrom, TTo>(MapperAction <TContext> action) { ((FuncBasedMap <TFrom, TTo, TContext>)GetMapper <TFrom, TTo>()).ConvertMethod = (from, to, context) => (TTo)action(from, to, context); }