Exemplo n.º 1
0
        /// <summary>
        /// Save records array to csv file.
        /// </summary>
        /// <param name="writer">The csv writer.</param>
        public void SaveToCSV(StreamWriter writer)
        {
            if (writer is null)
            {
                throw new ArgumentNullException($"{nameof(writer)} cannot be null.");
            }

            var csvWriter = new FileCabinetRecordCsvWriter(writer, this.records);

            csvWriter.Write();
        }
        /// <summary>
        /// Saves to CSV.
        /// </summary>
        /// <param name="writer">The writer.</param>
        public void SaveToCsv(StreamWriter writer)
        {
            FileCabinetRecordCsvWriter writeToFile = new FileCabinetRecordCsvWriter(writer);
            Type t = typeof(FileCabinetRecord);

            PropertyInfo[] info = t.GetProperties();
            writeToFile.WriteFields(info);
            foreach (var record in this.records)
            {
                writeToFile.Write(record);
            }
        }
        /// <summary>
        /// Saves to CSW.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <exception cref="ArgumentNullException">Throws when stream is null.</exception>
        public void SaveToCsw(StreamWriter stream)
        {
            if (stream is null)
            {
                throw new ArgumentNullException($"{nameof(stream)} must nit be null");
            }

            FileCabinetRecordCsvWriter writer = new FileCabinetRecordCsvWriter(stream);

            stream.WriteLine("Id,First Name,Last Name,Date of Birth,Department,Salary,Class");
            foreach (var item in this.records)
            {
                writer.Write(item);
            }
        }