public void WriteFile(string path, IConcordance corcondance) { if (!File.Exists(path)) { throw new FileNotFoundException("File not found"); } if (corcondance is null) { throw new Exception("Corcondance is null"); } File.WriteAllText(path, ""); using (StreamWriter fs = new StreamWriter(path, true, Encoding.Default)) { foreach (KeyValuePair <char, List <ConcordanceItem> > corcondanceItem in corcondance.GetEnumerator()) { fs.WriteLine("{0,18}", corcondanceItem.Key); foreach (var valueItem in corcondanceItem.Value) { fs.WriteLine(" {0,15} " + valueItem.Counter + ": " + String.Join(" ", valueItem.GetNumberLines()), valueItem.Word); } fs.WriteLine(); } } }
public static string Serialize(IConcordance model) { return(JsonConvert.SerializeObject(model)); }