首页 > Windows开发 > 详细

C#获得类的方法和方法参数

时间:2016-10-26 19:09:26      阅读:204      评论:0      收藏:0      [点我收藏+]
  Type t = typeof(CommonController);


            StringBuilder str = new StringBuilder();

            MethodInfo[] methors = t.GetMethods(BindingFlags.Instance | BindingFlags.Public);
            var md = t.GetCustomAttribute<System.ComponentModel.DescriptionAttribute>();
            str.AppendFormat("路由:" + t.Name).AppendLine("");
            str.AppendFormat("描述" + md.Description).AppendLine("");

            foreach (var v in methors)
            {

                var af = v.GetCustomAttribute<Models.Attribute.APIFunctionAttribute>();
                if (af != null)
                {
                    str.AppendFormat("\t功能标识:{0}", v.Name).AppendLine("");
                    str.AppendFormat("\t功能描述:{0}", af.Description).AppendLine("");
                    ParameterInfo[] ps = v.GetParameters();
                    str.AppendFormat("\t参数:总数{0}", ps.Length).AppendLine("");
                    foreach (ParameterInfo p in ps)
                    {
                        str.AppendFormat("\t\t名称{0}", p.Name).AppendLine("");
                        str.AppendFormat("\t\t类型{0}", p.ParameterType.FullName).AppendLine("");
                    }
                }

 

C#获得类的方法和方法参数

原文:http://www.cnblogs.com/GarsonZhang/p/6001317.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!