Ejemplo n.º 1
0
        public bool AddMapping(string sourceColumn, string index, string entityProperty, string defaultValue = null)
        {
            Guard.ArgumentNotEmpty(() => sourceColumn);

            var isAlreadyMapped = (entityProperty.HasValue() && _map.Any(x => x.Value.Property.IsCaseInsensitiveEqual(entityProperty)));

            if (isAlreadyMapped)
            {
                return(false);
            }

            _map[CreateSourceName(sourceColumn, index)] = new ColumnMappingValue
            {
                Property = entityProperty,
                Default  = defaultValue
            };

            return(true);
        }
Ejemplo n.º 2
0
        private TProp GetDefaultValue <TProp>(ColumnMappingValue mapping, string columnName, TProp defaultValue, ImportResult result = null)
        {
            if (mapping != null && mapping.Default.HasValue())
            {
                try
                {
                    return(mapping.Default.Convert <TProp>(_segmenter.Culture));
                }
                catch (Exception exception)
                {
                    if (result != null)
                    {
                        var msg = "Failed to convert default value '{0}'. Please specify a convertable default value. {1}";
                        result.AddWarning(msg.FormatInvariant(mapping.Default, exception.Message), this.GetRowInfo(), columnName);
                    }
                }
            }

            return(defaultValue);
        }