zoukankan      html  css  js  c++  java
  • 在asp.net页面中动态调用方法

    系统原来是通过webservice实现的,现在需要在webservice访问cookie, 但在webservice中没法调用cookie,后来发现可以通过下列方法实现:具体例子如下 :

    protected void Page_Load(object sender, EventArgs e)
        
    {
            
    //参数定义
            object[] args = new object[]{};

            Type type 
    = this.GetType();

            
    //动态调用方法,方法名可以通过参数传过来
            MethodInfo methodInfo = type.GetMethod("Test");

            
    if (methodInfo != null)
            
    {
                args 
    = new object[methodInfo.GetParameters().Length];
                
    //对方法名的参数进行赋值
                for (int i = 0; i < methodInfo.GetParameters().Length; i++)
                
    {
                    ParameterInfo param 
    = methodInfo.GetParameters()[i];
                    args[i] 
    = Request.QueryString[param.Name];
                }

                
    //执行方法
                methodInfo.Invoke(this, args);
            }

        }


        
    public void Test(string Id,string name)
        
    {
            
    //Response.Write(Request.Cookies[0].Value);
            Response.Write(Id + ":" + name);
        }


        
    public void TestA()
        
    {
            Response.Write(
    "dddd");
        }
  • 相关阅读:
    用场景来规划测试工作
    冲刺第二十天 到二十二天
    冲刺第十九天
    冲刺第十八天
    阅读《构建之法》第13-17章(包含读后感)
    冲刺第5,6天(5月25,26日)
    冲刺第四天(2天合一起当一篇随笔,明天会在这篇里继续更新)
    冲刺第二天
    作业5.2
    作业5.1
  • 原文地址:https://www.cnblogs.com/mini/p/891797.html
Copyright © 2011-2022 走看看