私はいくつかの既存のコードに取り組んでいます。数時間後、私はこの問題をメソッドピッカークラスに要約しました。このクラスをフォローするのは難しいと思います。このタイプのメソッドピッキング機能を簡単な方法で実現することは可能ですか?
public class MethodPicker
{
private delegate string SomeFunc(MethodPicker item);
static readonly Dictionary<string, SomeFunc> test = new Dictionary<string, SomeFunc>();
static MethodPicker()
{
test.Add("key1", Func1);
test.Add("key2", Func2);
test.Add("key3", Func3);
}
public string RunTest(string Name)
{
string somestring = test[Name].Invoke(this);
return somestring;
}
public static string Func1(MethodPicker entity)
{
return "func1 runs";
}
public static string Func2(MethodPicker entity)
{
return "func2 runs";
}
public static string Func3(MethodPicker entity)
{
return "func3 runs";
}
}