/// <summary> /// Method creates wrapper-object for tag /// </summary> /// <param name="tag">Key-word</param> /// <returns>Wrapper-object</returns> private Book Wrapper(string tag) { PropertyInfo[] bookProperties = Book.GetProperties(); string[] values = new string[bookProperties.Length]; for (int i = 0; i < bookProperties.Length; i++) { values[i] = tag; } return(new Book(values)); }
/// <summary> /// Method to save collection to file /// </summary> public void SaveFile() { using (BinaryWriter writer = new BinaryWriter(File.Open(path, FileMode.OpenOrCreate))) { PropertyInfo[] info = Book.GetProperties(); foreach (Book book in booksList) { for (int i = 0; i < info.Length; i++) { writer.Write((string)info[i].GetValue(book)); } } } }
/// <summary> /// Method to load collection from file /// </summary> public void LoadFile() { using (BinaryReader reader = new BinaryReader(File.Open(path, FileMode.OpenOrCreate))) { while (reader.PeekChar() > -1) { string[] values = new string[Book.GetProperties().Length]; for (int i = 0; i < values.Length; i++) { values[i] = reader.ReadString(); } booksList.Add(new Book(values)); } } }