예제 #1
0
 /// <summary>
 /// Saves collection of contacts to file
 /// </summary>
 /// <param name="collection">Collection to save</param>
 /// <param name="filepath">File to write to</param>
 public static void SaveSortedContactsToFile(IEnumerable <Contact> collection, string filepath)
 {
     using (StreamWriter writer = new StreamWriter(filepath))
     {
         foreach (Contact c in collection)
         {
             ContactIOManager.Write(c, writer);
         }
     }
 }
예제 #2
0
        /// <summary>
        /// Reads <see cref = "Contact" />s from file located at <paramref name="path"/>.
        /// </summary>
        /// <param name="path">File to read from</param>
        /// <returns>ArrayList of <see cref = "Contact" /> which was read</returns>
        /// <exception cref="System.Exception">Thrown when invalid input occurs.</exception>
        /// <exception cref="System.IO.IOException">Thrown when an I/O error occurs, i.e. file doesn't exist</exception>
        public static ArrayList ReadFile(string path)
        {
            ArrayList contacts = new ArrayList();

            using (StreamReader stream = new StreamReader(path))
            {
                while (stream.EndOfStream == false)
                {
                    contacts.Add(ContactIOManager.Read(stream));
                }
            }

            return(contacts);
        }