Hi Guys,
Will you help me on my concern? I want to perform code reuse for the snippet below using Generics. How can I turn this to a single method? I am still not that familiar with Generics.
public void ReadInputFiles(string sourcePath)
{
CompanyAddressInputFile path = new CompanyAddressInputFile();
path.Path = sourcePath;
string[] filePaths = GetFiles(path.Path);
foreach (string file in filePaths)
{
CompanyAddressInputFile companyAddressInputFile = new CompanyAddressInputFile();
companyAddressInputFile.Path = sourcePath;
companyAddressInputFile.Filename = Path.GetFileName(file);
ProcessFile(companyAddressInputFile);
}
}
public void ReadOutputFiles(string desPath)
{
CompanyAddressOutputFile path = new CompanyAddressOutputFile();
path.Path = desPath;
string[] filePaths = GetFiles(path.Path);
foreach (string file in filePaths)
{
CompanyAddressOutputFile companyAddressOutputFile = new CompanyAddressOutputFile();
companyAddressOutputFile.Path = desPath;
companyAddressOutputFile.Filename = Path.GetFileName(file);
UpdateAddress(companyAddressOutputFile);
}
}
{
CompanyAddressInputFile path = new CompanyAddressInputFile();
path.Path = sourcePath;
string[] filePaths = GetFiles
foreach (string file in filePaths)
{
CompanyAddressInputFile companyAddressInputFile = new CompanyAddressInputFile();
companyAddressInputFile.Path = sourcePath;
companyAddressInputFile.Filename = Path.GetFileName(file);
ProcessFile(companyAddressInputFile);
}
}
public void ReadOutputFiles(string desPath)
{
CompanyAddressOutputFile path = new CompanyAddressOutputFile();
path.Path = desPath;
string[] filePaths = GetFiles
foreach (string file in filePaths)
{
CompanyAddressOutputFile companyAddressOutputFile = new CompanyAddressOutputFile();
companyAddressOutputFile.Path = desPath;
companyAddressOutputFile.Filename = Path.GetFileName(file);
UpdateAddress(companyAddressOutputFile);
}
}
And, is below a good Generics method implementation?
public string[] GetFiles(T filePath)
{
string[] filePaths = Directory.GetFiles(filePath.ToString());
return filePaths;
}
{
string[] filePaths = Directory.GetFiles(filePath.ToString());
return filePaths;
}

Teemee Tang110 reputationPosted Sep 18, 2017, 12:29 AM EDT
Teemee Tang110 reputationPosted Sep 13, 2017, 9:00 AM EDT
Tapan PatelRank #614 · 3.9K reputationPosted Sep 13, 2017, 11:03 AM EDT
Tapan PatelRank #614 · 3.9K reputationPosted Sep 18, 2017, 5:33 AM EDT
Nilesh ShahRank #42 · 34.2K reputationPosted Sep 13, 2017, 8:00 AM EDT