Exemplo n.º 1
0
        string IMappingEngineRunner.FormatValue(ResolutionContext context)
        {
            TypeMap contextTypeMap = context.GetContextTypeMap();
            IFormatterConfiguration configuration = contextTypeMap != null
                        ? ConfigurationProvider.GetProfileConfiguration(contextTypeMap.Profile)
                                                : ConfigurationProvider.GetProfileConfiguration(ConfigurationStore.DefaultProfileName);

            object valueToFormat  = context.SourceValue;
            string formattedValue = context.SourceValue.ToNullSafeString();

            var formatters = configuration.GetFormattersToApply(context);

            foreach (var valueFormatter in formatters)
            {
                formattedValue = valueFormatter.FormatValue(context.CreateValueContext(valueToFormat));

                valueToFormat = formattedValue;
            }

            if (formattedValue == null && !((IMappingEngineRunner)this).ShouldMapSourceValueAsNull(context))
            {
                return(string.Empty);
            }

            return(formattedValue);
        }
Exemplo n.º 2
0
        bool IMappingEngineRunner.ShouldMapSourceCollectionAsNull(ResolutionContext context)
        {
            var typeMap = context.GetContextTypeMap();

            if (typeMap != null)
            {
                return(ConfigurationProvider.GetProfileConfiguration(typeMap.Profile).MapNullSourceCollectionsAsNull);
            }

            return(ConfigurationProvider.MapNullSourceCollectionsAsNull);
        }
Exemplo n.º 3
0
        bool IMappingEngineRunner.ShouldMapSourceValueAsNull(ResolutionContext context)
        {
            if (context.DestinationType.IsValueType)
            {
                return(false);
            }

            var typeMap = context.GetContextTypeMap();

            if (typeMap != null)
            {
                return(ConfigurationProvider.GetProfileConfiguration(typeMap.Profile).MapNullSourceValuesAsNull);
            }

            return(ConfigurationProvider.MapNullSourceValuesAsNull);
        }