-
Notifications
You must be signed in to change notification settings - Fork 0
/
CsvProvider.cs
38 lines (32 loc) · 1.02 KB
/
CsvProvider.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System;
using System.Globalization;
using System.IO;
using CsvHelper;
namespace DriftsHelper;
public class CsvProvider : IProvider
{
private static FileStreamOptions Options {get;} = new FileStreamOptions() {
Access = FileAccess.Read
};
public static string Filter { get; set; } = "*.csv";
public CsvProvider(string folderPath)
{
Comment = folderPath;
Spectra = new List<Spectrum>();
foreach (var item in Directory.EnumerateFiles(folderPath, Filter).OrderBy(x => x))
{
using TextReader t = new StreamReader(item, Options);
using CsvReader r = new(t, CultureInfo.InvariantCulture);
Spectrum s = new(Path.GetFileNameWithoutExtension(item));
r.Read();
r.ReadHeader();
while (r.Read())
{
s.Add(r.GetField<double>(0), r.GetField<double>(1));
}
Spectra.Add(s);
}
}
public List<Spectrum> Spectra { get; }
public string Comment { get; }
}