public void Apply(IReaderConfiguration config)
        {
            // see http://joshclose.github.io/CsvHelper/

            config.RegisterClassMap <RecordMap>();
            config.RegisterClassMap <MetadataMap>();
        }
Ejemplo n.º 2
0
        private void DefaultConfigureReader(IReaderConfiguration configuration)
        {
            configuration.HasHeaderRecord   = true;
            configuration.Delimiter         = ";";
            configuration.IgnoreReferences  = true;
            configuration.HeaderValidated   = null;
            configuration.MissingFieldFound = null;

            // https://github.com/JoshClose/CsvHelper/issues/670
            // HACK: it seems there's no built-in way to apply general settings for automatic type conversions,
            // so we gather the possible types and apply the necessary settings type by type.

            const BindingFlags allPublicInstanceMembers = BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Instance;

            var publicInstanceMemberTypes = _files
                                            .Select(file => file.EntityType)
                                            .SelectMany(type =>
                                                        type.GetProperties(allPublicInstanceMembers).Select(property => property.PropertyType).Concat(
                                                            type.GetFields(allPublicInstanceMembers).Select(property => property.FieldType)))
                                            .Distinct();

            foreach (var type in publicInstanceMemberTypes)
            {
                var options = configuration.TypeConverterOptionsCache.GetOptions(type);
                options.CultureInfo = configuration.CultureInfo;

                // consider "NULL" string as NULL value
                if (!type.IsValueType || Nullable.GetUnderlyingType(type) != null)
                {
                    options.NullValues.Add("NULL");
                }
            }
        }
Ejemplo n.º 3
0
        public void Apply(IReaderConfiguration config)
        {
            // see http://joshclose.github.io/CsvHelper/

            config.TrimOptions = TrimOptions.Trim;
            config.RegisterClassMap <RecordMap>();
            config.RegisterClassMap <GeminiMap>();
        }
Ejemplo n.º 4
0
        public static IReaderConfiguration ApplyStandardTopcatConfiguration(IReaderConfiguration config, string delimiter)
        {
            config.Delimiter             = delimiter;
            config.ReferenceHeaderPrefix = (memberType, memberName) => $"{memberName}.";
            config.TypeConverterCache.AddConverter <List <MetadataKeyword> >(new Exporter.MetadataKeywordConverter());
            config.TypeConverterCache.AddConverter <List <Extent> >(new Exporter.ExtentListConverter());

            return(config);
        }
        public CsvReader Create(TextReader textReader, bool hasHeaderRecord = true, string delimiter = ";")
        {
            IReaderConfiguration readerConfiguration = CreateCsvReaderConfiguration();

            readerConfiguration.HasHeaderRecord = hasHeaderRecord;
            readerConfiguration.Delimiter       = delimiter;

            return(new CsvReader(textReader, (CsvConfiguration)readerConfiguration));
        }
Ejemplo n.º 6
0
 private static void SetCsvReaderConfig(IReaderConfiguration config)
 {
     config.Delimiter             = "\t";
     config.PrepareHeaderForMatch = header => header?.Trim().ToLower();
     config.HeaderValidated       = null;
     config.MissingFieldFound     = null;
     //config.BadDataFound = null;
     config.Comment       = '#';
     config.AllowComments = true;
 }
 /// <summary>
 /// Registers the ClassMap that corresponds to the given Class.
 /// </summary>
 /// <param name="in_configuration">The CSV Reader Configuration.</param>
 /// <typeparam name="T">The class to map.</typeparam>
 /// <returns>The class map for the given type.</returns>
 public static void RegisterClassMapFor <T>(this IReaderConfiguration in_configuration) where T : ParquetParent
 {
     if (typeof(T) == typeof(Floor))
     {
         in_configuration.RegisterClassMap <FloorClassMap>();
     }
     else if (typeof(T) == typeof(Block))
     {
         in_configuration.RegisterClassMap <BlockClassMap>();
     }
     else if (typeof(T) == typeof(Furnishing))
     {
         in_configuration.RegisterClassMap <FurnishingClassMap>();
     }
     else if (typeof(T) == typeof(Collectible))
     {
         in_configuration.RegisterClassMap <CollectibleClassMap>();
     }
     else
     {
         Error.Handle($"No class map exists for {typeof(T)}");
     }
 }
Ejemplo n.º 8
0
 public void RegisterEvents(IReaderConfiguration configuration)
 {
     configuration.BadDataFound             = s => BadDataFound(new FlatFileLine(s), true);
     configuration.ReadingExceptionOccurred = ReadingExceptionOccurred;
 }
Ejemplo n.º 9
0
 public void Apply(IReaderConfiguration config)
 {
     ApplyStandardTopcatConfiguration(config, "\t");
     // do nothing else! for this import mapping we're going to use defaults
 }
Ejemplo n.º 10
0
 public ReaderRowMock(CsvConfiguration configuration)
 {
     Configuration = configuration;
 }
Ejemplo n.º 11
0
 public ReaderRowMock()
 {
     Configuration = new CsvConfiguration(CultureInfo.InvariantCulture);
 }