private static string[] ReadUntil(StreamReaderParser fe, string cad) { var res = new List<string>(); var c = fe.ReadLineTrim(); while ((c!= null) && !c.StartsWith(cad, StringComparison.CurrentCulture)) { res.Add(c); c = fe.ReadLineTrim(); } return res.ToArray(); }
public TaskFile(string file) { var reader = new StreamReaderParser(file, (a, i) => { switch (i) { case 0: return (a.StartsWith("///<Task>", StringComparison.CurrentCulture)) ? 1 : -1; case 1: if (a.StartsWith("///</Task>", StringComparison.CurrentCulture)) return 3; if (a.StartsWith("///!", StringComparison.CurrentCulture)) return 4; return 2; case 2: return (a.StartsWith("///</Task>", StringComparison.CurrentCulture)) ? 3 : 2; case 4: if (a.StartsWith("///</Task>", StringComparison.CurrentCulture)) return 3; if (a.StartsWith("///!", StringComparison.CurrentCulture)) return 4; return 2; default: return -1; } }, (a, i) => { switch (i) { case 2: return a.Trim().RemoveLeft("///",No).RemoveLeft("//",No); case 4: return a.Trim(); default: return null; } } ); while (!reader.EndOfStream) { var linea = reader.ReadLineTrim(); if (linea == null) break; Switch.OnTrue() .Case(linea.StartsWith("///!", StringComparison.CurrentCulture)).Do(()=>PreCode.Add(linea)) .Case(linea.StartsWith("<TaskClass:", StringComparison.CurrentCulture)).Do(()=> { var c = new TaskClass(linea.Between("<TaskClass:",">"),ReadUntil(reader,"</TaskClass")); if (string.IsNullOrEmpty(c.AttrName)) throw new Exception("Fichero mal formado"); TaskClasses.Add(c.AttrName, c); }) .Case(linea.StartsWith("<TaskMember:", StringComparison.CurrentCulture)).Do(() => { var c = new TaskMember(linea.Between("<TaskMember:", ">"), ReadUntil(reader, "</TaskMember")); if (string.IsNullOrEmpty(c.AttrName)) throw new Exception("Fichero mal formado"); TaskMembers.Add(c.AttrName, c); }) .Default(()=> { throw new Exception("Fichero mal formado"); }); } }