次のような関数階層を含む変数があります。
string str= "fun1(fun2(),fun3(fun4(fun5(34,33,'aa'),'value',fun6()))"
//この階層はデータベースから文字列として取得されます
System.reflectionをインポートし、invokeメソッドを使用して呼び出しましたが、関数が1つしかない場合にのみ機能しますfun1
。
上記の関数階層では、完全な式を1つの関数名として使用しています。
以下のコードを使用して、関数階層を呼び出しています。
public static string InvokeStringMethod(string typeName, string methodName)
{
// Get the Type for the class
Type calledType = Type.GetType(typeName);
// Invoke the method itself. The string returned by the method winds up in s
String s = (String)calledType.InvokeMember(
methodName,
BindingFlags.InvokeMethod | BindingFlags.Public |
BindingFlags.Static,
null,
null,
null);
// Return the string that was returned by the called method.
return s;
}
参照: http: //www.codeproject.com/KB/cs/CallMethodNameInString.aspx
どうしたらいいか教えてください。