public ObjectMapper <TSource, TTarget> Create <TSource, TTarget>(ObjectMappingData <TSource, TTarget> mappingData)
        {
            var mappingExpression = MappingDataSourceSetFactory.CreateFor(mappingData).BuildValue();

            if (mappingExpression == Constants.EmptyExpression)
            {
                return(null);
            }

            mappingExpression = MappingFactory
                                .UseLocalSourceValueVariableIfAppropriate(mappingExpression, mappingData.MapperData);

            var mapper = new ObjectMapper <TSource, TTarget>(mappingExpression, mappingData);

            if (_creationCallbacksByKey == null)
            {
                return(mapper);
            }

            var creationCallbackKey = new MapperCreationCallbackKey(mappingData.MapperData);

            if (_creationCallbacksByKey.TryGetValue(creationCallbackKey, out var creationCallback))
            {
                creationCallback.Invoke(mapper);
            }

            return(mapper);
        }
Ejemplo n.º 2
0
        private static int GetIndexOf(
            Type configurationType,
            ISimpleDictionary <Type, int> configurationIndexesByType,
            IDictionary <Type, ConfigurationData> configurationDataByType,
            ICollection <Type> checkedTypes)
        {
            if (configurationIndexesByType.TryGetValue(configurationType, out var index))
            {
                return(index);
            }

            InsertWithOrder(
                configurationDataByType[configurationType],
                configurationIndexesByType,
                configurationDataByType,
                checkedTypes);

            return(configurationIndexesByType[configurationType]);
        }