日期:2014-05-18 浏览次数:20489 次
protected string fun(int i) { string aa switch (i) { case 1: aa=web1.Service().doit(args,args2); return aa; break; case 2: aa=web1.Service().doit(args,args2); return aa; break; default: aa=web1.Service().doit(args,args2); return aa; break; }
------解决方案--------------------
protected string fun(int i) { string aa = string.Empty; switch (i) { case 1: aa=web1.Service().doit(args,args2); break; case 2: aa=web1.Service().doit(args,args2); break; default: aa=web1.Service().doit(args,args2); break; } return aa;
------解决方案--------------------
可以执行一个字符串,下面是例子
string test = "MyProc(10)";
string name = test.Substring(0, test.IndexOf('('));
string arg = test.Replace(name + "(", "").TrimEnd(')');
MethodInfo mi = typeof(Class1).GetMethod(name);
if (mi != null)
{
object[] os = new object[] { Convert.ToInt16(arg) };
mi.Invoke(null, os);
}
public static void MyProc(int n)
{
Console.Write(n);
Console.WriteLine("");
}
------解决方案--------------------
那只能用反射做了
------解决方案--------------------
估计要反射了..
------解决方案--------------------
参考一下吧.
using System; using System.Reflection; using System.Security; class MyClass { public int myInt = 0; public string myString = null; public MyClass() { } public void Myfunction(int i) { } } class Type_GetMethod { public static void Main() { try { MyClass MyObject = new MyClass(); MethodInfo myMethodInfo; // Get the type of MyClass. Type myType = MyObject.GetType(); // Get the method information for M