日期:2014-05-17  浏览次数:20402 次

怎么用反射动态调用方法?
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