using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Adaptation.FileHandlers.csv; public class Info { public string Operator { get; set; } public string SampleName { get; set; } public string SoftwareVersion { get; set; } public string DateTime { get; set; } public string SystemId { get; set; } public string SystemSite { get; set; } public string SamplePosition { get; set; } public string Units { get; set; } public string CommentLength { get; set; } public List Comments { get; set; } #nullable enable #pragma warning disable CA1834 internal static Info? GetInfo(string[] lines, int start, int stop) { Info? result; string first; string[] segments; int? secondStart = null; List values = new(); List comments = new(); StringBuilder stringBuilder = new(); for (int i = start; i < stop; i++) { segments = lines[i].Split(new string[] { "," }, StringSplitOptions.None); first = segments.First(); if (first == "Comment:") { secondStart = i + 1; break; } _ = stringBuilder.Append(first).Append(","); if (segments.Length > 1) values.Add(segments[1]); else values.Add(string.Empty); } string header = "Operator,Sample Name,Software Version,Date & Time,System ID,System Site,Sample Position,Units,Comment Length,"; if (secondStart is null || stringBuilder.Length != header.Length || stringBuilder.ToString() != header) result = null; else { result = new() { Operator = values[0], SampleName = values[1], SoftwareVersion = values[2], DateTime = values[3], SystemId = values[4], SystemSite = values[5], SamplePosition = values[6], Units = values[7], CommentLength = values[8], Comments = comments, }; for (int i = secondStart.Value; i < stop; i++) comments.Add(lines[i]); } return result; } }