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");
        }
  • 相关阅读:
    C语言不定参数
    C和C++中的不定参数
    C/C++ 中头文件相互包含引发的问题
    Makefile经典教程(掌握这些足够)
    C语言中volatile关键字的作用
    C++中字符数组与string的相互转换
    C++中 使用数组作为map容器VAlue值的解决方法
    sql 内连接、外连接、自然连接等各种连接
    网站小图标
    Eclipse:快捷
  • 原文地址:https://www.cnblogs.com/mini/p/891797.html
Copyright © 2011-2022 走看看