获取类中所有方法

        #region 获取所有方法
        /// <summary>
        /// 获取所有方法
        /// </summary>
        /// <returns></returns>
        public ActionResult GetMethod()
        {
            Dictionary<string, string> dics = new Dictionary<string, string>();
            Type type = typeof(KedaoJingLingController);
            foreach (MethodInfo methodInfo in type.GetMethods())
            {
                if (methodInfo.IsSecurityCritical)
                {
                    var paras = string.Empty;
                    foreach (var para in methodInfo.GetParameters())
                    {
                        paras += para.Name + "=" + para.ParameterType.Name + "&";
                    }
                    paras = paras.TrimEnd('&');
                    var mothodName = methodInfo.Name;

                    var description = methodInfo.GetCustomAttributes(typeof(DescriptionAttribute), true);
                    if (description.Length > 0)
                    {
                        mothodName = string.Format("{0} {1}", mothodName, (description[0] as DescriptionAttribute).Description);
                    }
                    dics.Add(mothodName, paras);
                }
            }
            return Json(dics);
        }
        #endregion

  

原文地址:https://www.cnblogs.com/wangjiayuan/p/4431947.html