Ejemplo n.º 1
0
        private ObjectMappingData(
            TSource source,
            TTarget target,
            int?enumerableIndex,
            ObjectMapperKeyBase mapperKey,
            IMappingContext mappingContext,
            IObjectMappingData declaredTypeMappingData,
            IObjectMappingData parent)
            : base(source, target, enumerableIndex, parent)
        {
            MapperKey               = mapperKey;
            MappingContext          = mappingContext;
            DeclaredTypeMappingData = declaredTypeMappingData;

            if (parent != null)
            {
                _parent = parent;
                return;
            }

            IsRoot = true;

            if (IsPartOfDerivedTypeMapping)
            {
                return;
            }

            _mapper = MapperContext.ObjectMapperFactory.GetOrCreateRoot(this);

            if (MapperData.MappedObjectCachingNeeded)
            {
                _mappedObjectsBySource = new Dictionary <object, List <object> >(13);
            }
        }
Ejemplo n.º 2
0
        public ObjectMapper(Expression mapping, IObjectMappingData mappingData)
        {
            _mapperKey = mappingData.MapperKey;
            Mapping    = mapping;
            MapperData = mappingData.MapperData;

            var mapperDataContext = MapperData.Context;

            if (mapperDataContext.Compile)
            {
                _mapperFunc = GetMappingLambda().Compile();
            }
            else if (mapperDataContext.NeedsRuntimeTypedMapping)
            {
                MapperData.Mapper = this;
            }

            if (mapperDataContext.NeedsRuntimeTypedMapping)
            {
                _subMappersByKey = Cache.CreateNew <ObjectMapperKeyBase, IObjectMapper>();
            }

            if (MapperData.HasRepeatedMapperFuncs)
            {
                _repeatedMappingFuncsByKey = Cache.CreateNew <ObjectMapperKeyBase, IRepeatedMapperFunc>();
                MapperData.Mapper          = this;

                CacheRepeatedMappingFuncs();
            }
        }
Ejemplo n.º 3
0
        public ObjectMapper(
            Expression <MapperFunc <TSource, TTarget> > mappingLambda,
            IObjectMappingData mappingData)
        {
            _mapperKey    = mappingData.MapperKey;
            MappingLambda = mappingLambda;
            MapperData    = mappingData.MapperData;

            if (MapperData.Context.Compile)
            {
                _mapperFunc = mappingLambda.Compile();
            }
            else if (MapperData.Context.NeedsSubMapping)
            {
                MapperData.Mapper = this;
            }

            if (MapperData.Context.NeedsSubMapping)
            {
                _subMappersByKey = MapperData.MapperContext.Cache.CreateNew <ObjectMapperKeyBase, IObjectMapper>();
            }

            if (MapperData.HasRepeatedMapperFuncs)
            {
                _repeatedMappingFuncsByKey = MapperData.MapperContext.Cache.CreateNew <ObjectMapperKeyBase, IRepeatedMapperFunc>();
                MapperData.Mapper          = this;

                CacheRepeatedMappingFuncs();
            }
        }
Ejemplo n.º 4
0
 public ObjectMappingData(
     TSource source,
     TTarget target,
     int?enumerableIndex,
     ObjectMapperKeyBase mapperKey,
     IMappingContext mappingContext,
     IObjectMappingData parent)
     : this(
         source,
         target,
         enumerableIndex,
         mapperKey,
         mappingContext,
         null,
         parent)
 {
 }
        private static IObjectMappingData Create <TDeclaredSource, TDeclaredTarget>(
            TDeclaredSource source,
            TDeclaredTarget target,
            int?enumerableIndex,
            ObjectMapperKeyBase mapperKey,
            IObjectMappingData parent)
        {
            var mappingData = Create(
                source,
                target,
                enumerableIndex,
                mapperKey.MappingTypes,
                parent.MappingContext,
                parent);

            mappingData.MapperKey = mapperKey;

            return(mappingData);
        }
Ejemplo n.º 6
0
        private static ObjectMappingData <TSource, TTarget> CreateMappingData <TSource, TTarget>(
            TSource source,
            TTarget target,
            int?enumerableIndex,
            ObjectMapperKeyBase mapperKey,
            IObjectMappingDataUntyped parent)
        {
            var mappingDataParent = (IObjectMappingData)parent;

            return(new ObjectMappingData <TSource, TTarget>(
                       source,
                       target,
                       enumerableIndex,
                       mapperKey.MappingTypes,
                       mappingDataParent.MappingContext,
                       mappingDataParent)
            {
                MapperKey = mapperKey
            });
        }
Ejemplo n.º 7
0
        public IRootMapperKey EnsureRootMapperKey()
        {
            MapperKey = MappingContext.RuleSet.RootMapperKeyFactory.CreateRootKeyFor(this);

            return((IRootMapperKey)MapperKey);
        }
Ejemplo n.º 8
0
 protected bool SourceHasRequiredTypes(ObjectMapperKeyBase otherKey)
 => (_sourceMemberTypeTester == null) || _sourceMemberTypeTester.Invoke(otherKey.MappingData);
Ejemplo n.º 9
0
 protected bool TypesMatch(ObjectMapperKeyBase otherKey) => otherKey.MappingTypes.Equals(MappingTypes);
Ejemplo n.º 10
0
        public IRootMapperKey EnsureRootMapperKey()
        {
            MapperKey = MappingContext.RuleSet.RootMapperKeyFactory.Invoke(this);

            return((IRootMapperKey)MapperKey);
        }