I have a class that only has one method. This method has to read csv file, do some work concerning internal logic (check if item already exists, do some transformations, etc.) and finally write all data to a database. I am using a nested class for storing data from csv file as a list of objects. It looks something like this:
public class Importer
{
public void Import(string path)
{
using(var reader = File.OpenText(path))
{
var csv = new CsvReader(reader);
var items = csv.GetRecords<ItemCsvModel>().ToList();
//do some work and insert items to db
}
}
private class ItemCsvModel
{
public int Id {get; set;}
public string Name {get; set;}
public string Description {get; set;}
}
}
Code reviewer didn't like using nested classes told me that it would be better if this class would be moved to another file. I think that this class is just an internal implementation detail and it has no reason to be visible outside the Importer class. I could've just as easily read that csv file without using any class by simply doing something like this:
var id = csv.GetField<int>("Id");
var name = csv.GetField<string>("Name");
var description = csv.GetField<string>("Description");
But I chose another approach. At the moment there are no other places where csv files are read and I doubt it will change any time soon so I am not repeating any class declarations over and over again. What are your thoughts?