首页

获取类中所有方法

        #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

  

posted @ 2015-04-16 14:03  HTTP.POST.COM  阅读(416)  评论(0编辑  收藏  举报
页脚