有一种方法可以返回一个表格,其中包含在程序文件夹中找到的 csv 文件的名称:
public static List<string> GetListOfTables() { var tables = new List<string>(); do { tables = Directory.GetFiles(".", "*.csv").Select(file => Path.GetFileName(file)).ToList(); if (tables.Count == 0) { Output.Invoke("\nNo .csv files are found, " + "please put a table csv file in the program folder and press <Enter> to continue"); while (Console.ReadKey(true).Key != ConsoleKey.Enter) { } } } while (tables.Count == 0); return tables; }
它具有内置验证(而不是排除),如果没有找到文件,用户需要将文件复制到文件夹并按下一个键。
这个方法有单一职责(最终返回工作表,检查只是一个检查)还是多个(返回工作表并检查用户操作的正确性)?
是否可以使用验证块创建单独的ValidationCsvFiles方法,然后将其包含或委托给 main 方法?
- 有一个类返回包含特定文件数据的工作表
static class CsvParser
{
public static List<string> GetListOfTables() { }
public static List<List<object>> GetTable(string tableName) { }
}
此类具有单一职责(导致返回带有数据的工作表,带有文件列表的工作表是辅助工具)或多个(返回带有数据的工作表和带有文件的工作表)
毕竟,一个有文件的工作表可以在另一个类中实现吗?