Beispiel #1
0
        public IObjectMapper GetOrCreateMapper()
        {
            if (_mapper != null)
            {
                return(_mapper);
            }

            _mapper = MapperContext.ObjectMapperFactory.Create(this);

            MapperKey.MappingData = null;

            if (_mapper == null)
            {
                return(null);
            }

            if (MapperContext.UserConfigurations.ValidateMappingPlans)
            {
                // TODO: Test coverage for validation of standalone child mappers
                MappingValidator.Validate(_mapper.MapperData);
            }

            StaticMapperCache <TSource, TTarget> .AddIfAppropriate(_mapper, this);

            return(_mapper);
        }
        public ObjectMapper <TSource, TTarget> GetOrCreateRoot <TSource, TTarget>(ObjectMappingData <TSource, TTarget> mappingData)
        {
            if (StaticMapperCache <TSource, TTarget> .TryGetMapperFor(mappingData, out var mapper))
            {
                return(mapper);
            }

            var rootMapperKey = mappingData.EnsureRootMapperKey();

            mapper = (ObjectMapper <TSource, TTarget>)_rootMappersCache.GetOrAdd(
                rootMapperKey,
                key => key.MappingData.GetOrCreateMapper());

            return(mapper);
        }