C#根据字符串名称 得到对应的方法

  public string GetMethod(string methodName, BookingRequest bookingId)
        {
            EmailTemplate p1 = new EmailTemplate();//
            Type t = p1.GetType();
   var mi = t.GetMethod(methodName, new Type[] { typeof(BookingRequest) });  //得到对应的方法 
            //通过反射执行ReturnAutoID方法,返回AutoID值
            object body= mi.Invoke(p1, new object[] { bookingId });//方法和参数
            return body<span style="font-family: Arial, Helvetica, sans-serif;">.ToString();</span>
        }

猜你喜欢

转载自www.cnblogs.com/wangchuang/p/9813884.html