I\'m using the following right now:
foreach (string file in files) {
switch (filetype.Value) {
case \"ReadFile\":
ReadFile(file);
You could keep a Dictionary
of delegates, as the simplest way:
Dictionary> fileReaders = new Dictionary>() {
{"ReadFile", ReadFile},
{"ReadOfficeWordFile", ReadOfficeWordFile},
{"ReadOfficeExcelFile", ReadOfficeExcelFile},
{"ReadPDFFile", ReadPDFFile}
};
Then call it like this:
fileReaders[fileType.Value](file);
Depending on what your methods return, you may have to change the type of the delegate (Action
means void something(string someparam)
as a method signature, for example) as well.