How can I call a generic method on an injected class without informing the parent class of the generic type?-Collection of common programming errors
Below is the implementation of a dependency that is injected into another class.
public class CsvDataProvider : ICsvDataProvider
{
readonly ICsvReaderFactory _factory;
public CsvDataProvider(ICsvReaderFactory factory)
{
_factory = factory;
}
public IEnumerable GetData(string filepath) where TRecord : class
{
var reader = _factory.CreateCsvReader(filepath);
return reader.GetRecords();
}
}
The reader that is created by the factory will read all lines in a CSV file and convert each line to an instance of TRecord. I do not own the reader code and can not change the GetRecords() method.
This is where I am stuck:
public class CsvDataMigrationController
{
readonly ICsvDataProvider _provider;
readonly ICsvDataMigration _migration;
public CsvDataMigrationController(ICsvDataProvider provider, ICsvDataMigration migration)
{
_provider = provider;
_migration = migration;
}
public void ProcessFile(string path)
{
var records = _provider.GetData(path); //