zoukankan      html  css  js  c++  java
  • 反射流程

     public Type RequestType { get; private set; } // 请求的类型        

    public Object Object { get; private set; } // 请求的对象        

    public MethodInfo Method { get; private set; }  // 请求的方法        

    public Object[] Parameters { get; private set; } // 请求的参数集合        

    public String TypePart { get; private set; }   // 请求的类型名称部分        

    public String MethodPart { get; private set; } // 请求的方法名部分

    TypePart = pairts[0];       //类名前缀

    MethodPart = pairts[1];  //方法名

    string assembly = System.Configuration.ConfigurationManager.AppSettings["MobileInterfaces"];

    //获取namespace路径,eg:Common.Web.Interfaces.Demo.Interfaces.{0}Service,Common.Web.Interfaces.Demo

    string typeName = string.Format(assembly, TypePart);

    //补全路径

     Type t = Type.GetType(typeName, false, true);//namespace路径,是否抛出异常,是否区分大小写

    RequestType = t;

    Method = t.GetMethod(pairts[1]); //获取方法

    //填充参数

    ParameterInfo[] pis = Method.GetParameters();//获取参数

    Parameters = new Object[pis.Length];

     Parameters = new Object[pis.Length];                  

     for (int i = 0; i < pis.Length; i++)                    

       {                       

          ParameterInfo info = pis[i];

                 val = Convert.ChangeType(context.Request[info.Name], info.ParameterType));

            //context.Request[info.Name],从url获取值

                  Parameters[i] = val;             

      }

      Object = Activator.CreateInstance(RequestType);//获取参数列表

     Object val = bag.Method.Invoke(bag.Object, bag.Parameters);//执行便获取返回值

    //轮询方式获取方法

     private MethodInfo FindMethod(Type t, string name)        

    {            

      var list = t.GetMethods();            

      foreach (MethodInfo method in list)            

        {               

            if (method.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase))                

            {                    

              return method;                

            }            

        }            

      return null;        

    }

  • 相关阅读:
    CF1474C Array Destruction 题解 贪心
    洛谷P1854 花店橱窗布置 题解 2D/0D型动态规划
    POJ1704 Georgia and Bob 题解 阶梯博弈
    HDU1848 Fibonacci again and again 题解 SG函数
    SG函数简要学习笔记
    洛谷P2868 [USACO07DEC]Sightseeing Cows G 题解 01分数规划+SPFA判负环
    洛谷P4322 [JSOI2016]最佳团体 题解 01分数规划+树上背包
    从零开发SIP客户端(Windows)踩坑实录
    richedit禁用输入法的实现
    VS2013无法加载解决方案中的项目(转)
  • 原文地址:https://www.cnblogs.com/hongfu/p/4323756.html
Copyright © 2011-2022 走看看