I\'m using the following right now:
foreach (string file in files) {
switch (filetype.Value) {
case \"ReadFile\":
ReadFile(file);
If you're looking for a way to avoid the explicit mapping of method names to string values you could use reflection to do dynamic method invocation (this assumes filetype.Value is of type String
)
String method_name = String.Empty;
foreach (string file in files) {
method_name = filetype.Value;
System.Reflection.MethodInfo method = this.GetType().GetMethod(method_name);
method.Invoke(this, new object[]{file});
}