莫里卡斯

记忆想是倒在掌心的水,不论你摊开还是紧握,终究还是会从指缝中一滴一滴,流淌干净!
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

反射调用传入字符串方法

Posted on 2013-11-24 09:59  莫里卡斯  阅读(86)  评论(0)    收藏  举报

using System;

using System.Collections.Generic;

using System.Linq; using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Reflection; using ClassLibrary1;

namespace WebApplication1 {    

   public partial class _Default : System.Web.UI.Page    

    {        

       protected void Page_Load(object sender, EventArgs e)      

      {              

             Type _type = this.GetType();            

            _type.GetMethod("SetUserInfo").Invoke(this, null);            

            String _context = _type.GetMethod("GetName").Invoke(this, new Object[] { }) as String;                

       }        

       public void SetUserInfo()        

      {            

        HttpContext.Current.Session["Name"] = "张三";        

      }

           public String GetName()        

      {            

        String _Name = HttpContext.Current.Session["Name"].ToString();            

        return _Name;        

       }    

     }

   }