怎么用反射动态调用方法?
- C# code
MethodInfo m = this.GetType().GetMethod("GetTitle"); if (m != null) { string text = m.Invoke(this, new object[] { }).ToString(); return text; } else { return "error"; } // 上面的代码是在 aspx.cs文件中的,调用的方法 GetTitle() 是在该 aspx.cs 继承的类中的 // m 总是为 null ,不能实例化这个该怎么写?求解决
[解决办法]
请确保GetTitle方法不是私有方法,修饰符不要是private/protected,改为public