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