示例#1
0
        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));
            }
        }
示例#2
0
        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));
            }
        }
示例#3
0
 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;
     }
 }
示例#4
0
 public IMappingCollection <TFrom, TTo, TContext> SetMember(MemberInfo to, MapperAction <TContext> getter)
 {
     return(SetMember(new[] { to }, getter));
 }
示例#5
0
        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);
        }
示例#6
0
 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 });
 }
示例#7
0
 private void InternalSetMapper <TFrom, TTo>(MapperAction <TContext> action)
 {
     ((FuncBasedMap <TFrom, TTo, TContext>)GetMapper <TFrom, TTo>()).ConvertMethod = (from, to, context) => (TTo)action(from, to, context);
 }