Пример #1
0
 /// <summary>
 /// EN: Logs a list of objects(class) to an existing CSV Log file. The properties in the object(class) must have a toString() functionality.
 /// JA: オブジェクトリスト(クラス)をCSV形式に変換します。変換したCSVの内容をもとに、既存のCSVファイルに追加されます。
 /// 作成します。オブジェクト(クラス)のプロパティーはtoStringのメソッドが必要です。
 /// </summary>
 /// <param name="objectlist">A list of object. // オブジェクトリスト</param>
 /// <param name="separator">CSV Separator. // CSVのセパレータ</param>
 /// <typeparam name="T">The 1st type parameter.// 与えたオブジェクトのT型</typeparam>
 private static void AppendToCSVFile <T>(IEnumerable <T> objectlist, string filepath, string separator = ",")
 {
     //using (TextWriter tw = File.AppendText(filepath))
     using (var tw = new StreamWriter(filepath, true, Encoding.UTF8)) // File.AppendText(filepath))
     {
         foreach (var line in BasicCSVHelpers.ToCsv(objectlist, separator, false))
         {
             tw.WriteLine(line);
         }
     }
 }
 /// <summary>
 /// EN: Logs a list of objects(class) to a new CSV Log file. The properties in the object(class) must have a toString() functionality.
 /// JA: オブジェクトリスト(クラス)をCSV形式に変換します。変換したCSVの内容をもとに、CSVファイルを常に新規
 /// 作成します。オブジェクト(クラス)のプロパティーはtoStringのメソッドが必要です。
 /// </summary>
 /// <param name="objectlist">A list of object. // オブジェクトリスト</param>
 /// <param name="separator">CSV Separator. // CSVのセパレータ</param>
 /// <typeparam name="T">The 1st type parameter.// 与えたオブジェクトのT型</typeparam>
 private static void LogToNewCSVFile <T>(IEnumerable <T> objectlist, string separator = ",")
 {
     //using (TextWriter tw = File.CreateText(GetCSVFilePath()))
     using (var tw = new StreamWriter(GetCSVFilePath(), false, Encoding.UTF8)) // File.CreateText(GetCSVFilePath()))
     {
         foreach (var line in BasicCSVHelpers.ToCsv(objectlist, separator, true))
         {
             tw.WriteLine(line);
         }
     }
 }
 /// <summary>
 /// EN: Logs an object(class) to an existing CSV Log file. The properties in the object(class) must have a toString() functionality.
 /// JA: オブジェクト(クラス)をCSV形式に変換します。変換したCSVの内容をもとに、既存のCSVファイルに追加されます。
 /// 作成します。オブジェクト(クラス)のプロパティーはtoStringのメソッドが必要です。
 /// </summary>
 /// <param name="obj">Object. // オブジェクト</param>
 /// <param name="separator">CSV Separator. // CSVのセパレータ</param>
 /// <typeparam name="T">The 1st type parameter.// 与えたオブジェクトのT型</typeparam>
 private static void LogAppendToCSVFile <T>(T obj, string separator = ",")
 {
     //using (TextWriter tw = File.AppendText(GetCSVFilePath()))
     using (var tw = new StreamWriter(GetCSVFilePath(), true, Encoding.UTF8)) // File.AppendText(GetCSVFilePath()))
     {
         foreach (var line in BasicCSVHelpers.ToCsv(obj, separator, false))
         {
             tw.WriteLine(line);
         }
     }
 }
Пример #4
0
        /// <summary>
        /// EN: Logs a list of objects(class) to a new CSV Log file. The properties in the object(class) must have a toString() functionality.
        /// JA: オブジェクトリスト(クラス)をCSV形式に変換します。変換したCSVの内容をもとに、CSVファイルを常に新規
        /// 作成します。オブジェクト(クラス)のプロパティーはtoStringのメソッドが必要です。
        /// </summary>
        /// <param name="objectlist">A list of object. // オブジェクトリスト</param>
        /// <param name="separator">CSV Separator. // CSVのセパレータ</param>
        /// <typeparam name="T">The 1st type parameter.// 与えたオブジェクトのT型</typeparam>
        private static void WriteToNewCSVFile <T>(IEnumerable <T> objectlist, string filepath, string separator = ",", bool overwrite = false)
        {
            if (overwrite)
            {
                FileHelpers.DeleteFileIfExists(filepath);
            }

            //using (TextWriter tw = File.CreateText(filepath))
            using (var tw = new StreamWriter(filepath, false, Encoding.UTF8)) // File.CreateText(filepath))
            {
                foreach (var line in BasicCSVHelpers.ToCsv(objectlist, separator, true))
                {
                    tw.WriteLine(line);
                }
            }
        }
        public static List <T> Read <T>(string filePath, Encoding encoding, int startFromLine = 0, bool ignoreNonCsv = true)
        {
            var csvDict = BasicCSVHelpers.Read(filePath, encoding, startFromLine, ignoreNonCsv);

            return(BasicCSVHelpers.CSVTo <T>(csvDict));
        }