public IEnumerable <Student> Read(string path, out List <string> fieldNames) { List <Student> students = new List <Student>(); bool firstString = true; fieldNames = new List <string>(); using (StreamReader streamReader = new StreamReader(path)) { while (!streamReader.EndOfStream) { string pattern = streamReader.ReadLine(); List <string> patterns = StudentsCsvParser.ParsePattern(pattern).ToList(); if (firstString) { fieldNames = patterns; firstString = false; } else { if (patterns.Count != fieldNames.Count) { throw new MarkFieldException("Incorrect count of marks"); } Student student = pattern.ParseStudent(); student.Validate(); students.Add(student); } } } return(students); }
public static void Validate(string fieldNames) { List <string> list = StudentsCsvParser.ParsePattern(fieldNames).ToList(); if (list.Count() < 3) { throw new FieldNameException(" not enouch columns"); } if ((!list[0].Equals("Фамилия") || !list[1].Equals("Имя") || !list[2].Equals("Отчество")) && (!list[0].Equals("Surname") || !list[1].Equals("Name") || !list[2].Equals("Middle Name"))) { throw new FieldNameException(" Wrong name of first 3 columns"); } }