As I think, you can create a common contract (interface) for these linear classes and use, for example, a common method.
IEnumerable<IDataLine> GetLines<T>(Func<object> parseFunction)
{
...
var dataLine = parseFunction(line);
if (dataLine == null)
{
continue;
}
...
}
Or you can create an IParser and enter it in a method
IEnumerable<IDataLine> GetLines<T>(IParser parser)
{
...
if (!parser.CanParse(line))
{
continue;
}
var dataLine = parser.Parse(line);
...
}
The last example is more like a strategy template.
source
share