示例#1
0
 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());
                 }
             }
         }
     }
 }
示例#2
0
 public BookListService(BookCollection books)
 {
     this.books = books;
 }