I have two methods which are very similar apart form the fact that the second method partially extends the functionality of the first method. For example the methods are below:
private void ExtendTable(FileInfo file, string columnToCopy, string columnNewName)
{
var data = File.ReadAllLines(file.FullName).ToArray();
if (data[1].Contains(columnToCopy))
{
var content = data[0] + Environment.NewLine + data[1] + columnNewName + Environment.NewLine + data[2];
}
}
private void ExtendTable(FileInfo file, string columnToCopy, string columnNewName, string secondColumnToCopy, string secondColumnNewName)
{
var data = File.ReadAllLines(file.FullName).ToArray();
if (data[1].Contains(columnToCopy) && data[1].Contains(secondColumnToCopy))
{
var content = data[0] + Environment.NewLine + data[1] + columnNewName + secondColumnNewName + Environment.NewLine + data[2];
}
}
As can be seen the second method slightly extends the functionality of the first. I plan on adding functionality which will print this back into a file, however my question is that this is quite repetitive and breaks DRY principle. How can I refactor these methods so there is less duplication while still ensuring they both work as intended.
Thanks