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


  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("");
                    }
                }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM