public static IEnumerable <CLLIEntity> Parse(string path) { using (var file = new StreamReader(path)) { string line; while ((line = file.ReadLine()) != null) { if (string.IsNullOrWhiteSpace(line)) { continue; } if (line.TrimStart().StartsWith("#")) { continue; } var parse = line.Split(new char[] { '\t' }); var entity = CLLIEntity.Parse(parse); yield return(entity); } } }
public static CLLIEntity Parse(string[] parts) { var entity = new CLLIEntity(); if (parts.Length < 4) { throw new ArgumentException("Expecting at least 4 columns as input"); } entity.CLLICode = parts[0]; int geonameId; if (int.TryParse(parts[3], out geonameId)) { entity.GeonameId = geonameId; } else { throw new ArgumentException("Could not parse Geonames ID"); } return(entity); }