I have the following:
foreach(var file in today.GetFiles())
{
if(file.Length > 0 && file.Extension == ".txt")
{
switch (file.Name)
{
case "realy_long_ugly_file_name_0":
//do something
break;
case "realy_long_ugly_file_name_1":
//do something else
break;
}
}
}
I have come across this post and thought I could clean up my code using an interface
. Would this be the right application for this situation? I have set up the interface and the inheritance but don't quite know how to proceed.
I understand the interface is calling different a class
based on what IPizza
member is in the IList<IPizza>
. I have a hard time understanding how I can pass in file.Name
(formerly done with a switch/case
) to my interface
to call different classes.
interface IMyFiles
{
void Process(FileInfo file);
}
public class FileName0 : IMyFiles
{
void IMyFiles.Process(FileInfo file)
{
//do somthing specific to FileName0
}
}
public class FileName1 : IMyFiles
{
void IMyFiles.Process(FileInfo file)
{
//do somthing specific to FileName1
}
}