silentthread2k
asked on
C#, Generic, Reuse of file enumeration
I'm trying to use my FileWorks class below to tell me if a directory has a certain file extension.
I'm trying to be as generic as possible and reuse the function...
GetFilesDoSomething
I'm not sure how to approach this one. This is the code I have below.
Does not look like it would work if I were to call it...
FileWorks filework = new FileWorks();
filework.GetFilesDoSomethi ng(directo ry, CheckDirectoryForFilesWith Extension) ;
How can I pass the bool result back accross soo many functions?
I'm trying to be as generic as possible and reuse the function...
GetFilesDoSomething
I'm not sure how to approach this one. This is the code I have below.
Does not look like it would work if I were to call it...
FileWorks filework = new FileWorks();
filework.GetFilesDoSomethi
How can I pass the bool result back accross soo many functions?
public class FileWorks
{
bool CheckDirectoryForFilesWithExtension(FileInfo fi)
{
if (fi.Extension == "tif")
{
return true;
}
}
public void GetFilesDoSomething(string DirName, Action<FileInfo> method)
{
DirectoryInfo d = new DirectoryInfo(DirName);
FileInfo[] f = d.GetFiles();
foreach (FileInfo fi in f)
{
method.Invoke(fi);
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Check this out:
https://www.experts-exchange.com/questions/24247143/Simple-calculator-using-delegates.html