コード例 #1
0
ファイル: DataCsvFile.cs プロジェクト: Guido1234/CodeLibrary
        public override string Execute(StringTemplateItem template)
        {
            string file = PathUtility.ParseSpecialFoldersNames(this.File, ParseSpecialFolderOption.WildCardToRealPath);

            string[]      values = new string[0];
            StringBuilder sb     = new StringBuilder();

            if (Utils.IsFileOrDirectory(file) == Utils.FileOrDirectory.File)
            {
                using (CsvStreamReader reader = new CsvStreamReader(file))
                {
                    reader.Separator = ',';

                    while (!reader.EndOfCsvStream) // Do not use EndOfStream
                    {
                        string line = reader.ReadLine();
                        values = Utils.SplitEscaped(line, reader.Separator, '"');

                        template.IsLastCommand = (reader.EndOfCsvStream && this.IsLastCommand);
                        sb.Append(template.Format(line, this.Data, values));
                    }
                    reader.Close();
                }
            }
            return(sb.ToString());
        }