Beispiel #1
0
        public void AddMapping(string sourceName, string index, string mappedName, string defaultValue = null)
        {
            Guard.ArgumentNotEmpty(() => sourceName);
            Guard.ArgumentNotEmpty(() => mappedName);

            var key = CreateSourceName(sourceName, index);

            _map[key] = new ColumnMappingItem
            {
                SoureName  = key,
                MappedName = mappedName,
                Default    = defaultValue
            };
        }
Beispiel #2
0
        private TProp GetDefaultValue <TProp>(ColumnMappingItem mapping, 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. Column: {1}";
                        result.AddWarning(msg.FormatInvariant(mapping.Default, exception.Message), this.GetRowInfo(), mapping.SoureName);
                    }
                }
            }

            return(defaultValue);
        }