备忘-反射调用Private方法

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ReflectCallPrivateMethod
{
    class Program
    {
        static void Main(string[] args)
        {
            BasePage pb = new BasePage();

            Type ty = pb.GetType();
            System.Reflection.MethodInfo m = ty.GetMethod("Insert", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            m.Invoke(pb, null);

            Console.ReadLine();
        }
    }

    class BasePage
    {
        private void Insert()
        {
            Console.WriteLine("擦 , 怎么跑这么快");
        }
    }
}

  

posted @ 2013-04-18 16:29  Go和分布式IM  阅读(160)  评论(0编辑  收藏  举报