public void SaveDataToFile(BookCollection books) { using (var writer = new BinaryWriter(File.Open(fileName, FileMode.Create))) { foreach (var book in books) { using (var memoryStream = new MemoryStream()) { var serializer = new DataContractJsonSerializer(typeof(Book)); serializer.WriteObject(memoryStream, book); memoryStream.Position = 0; using (var streamReader = new StreamReader(memoryStream)) { writer.Write(streamReader.ReadToEnd()); } } } } }
public BookListService(BookCollection books) { this.books = books; }