summary

Posted kexb

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了summary相关的知识,希望对你有一定的参考价值。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace ConsoleApplication31
{


    /// <summary>
    /// 类注释辅助类
    /// </summary>
    public class ClassSummary
    {
        /// <summary>
        /// 类注释的构造函数
        /// </summary>
        public ClassSummary()
        {
            MethodSummaryDictionary = new Dictionary<string, string>();

        }
        /// <summary>
        /// 类名
        /// </summary>
        public string ClassName { get; set; }
        /// <summary>
        /// 每个类有N个方法 key:方法名 value:方法注释
        /// </summary>
        public Dictionary<string, string> MethodSummaryDictionary { get; set; }

    }
    class Program
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            ExtractInterfaceMthod2();
            Console.Read();
        }

        private static void ExtractInterfaceMthod()
        {
            var types = Assembly.Load("ClassLibrary1").GetTypes();
            StringBuilder sb = new StringBuilder();
            string str = "";
            string calfunc = "";
            foreach (var item in types)
            {
                if (item.Name == "IUser1EngineController")
                {
                    var methods = item.GetMethods().ToList();

                    foreach (MethodInfo m in methods)
                    {
                        var returntype = m.ReturnType.Name;
                        string methodName = m.Name;
                        if (string.Compare(returntype, "void", true) == 0)
                        {
                            returntype = "void";
                        }
                        str = $"public {returntype} {methodName} ( ";
                        calfunc = $" {methodName} ( ";

                        var parameters = m.GetParameters().ToList();
                        foreach (ParameterInfo parameter in parameters)
                        {
                            string pn = parameter.Name;
                            string ptype = parameter.ParameterType.ToString();
                            bool isout = false;
                            if (ptype.EndsWith("&"))
                            {
                                isout = true;
                                ptype = $"out {ptype.TrimEnd(‘&‘)}";
                            }
                            str += ptype + " " + pn + ",";
                            if (isout)
                            {
                                pn = "out " + pn;
                            }
                            calfunc += pn + ",";
                        }
                        str = str.TrimEnd(,);
                        string isreturn = returntype != "void" ? "return" : "";
                        calfunc = $"{isreturn} valuationCal." + calfunc.TrimEnd(,) + ");";

                        str += ")
{
" + calfunc + "
}";

                        sb.Append("
" + str);

                    }


                }

            }
            var str1 = sb.ToString();
            Console.WriteLine(str1);
        }

        private static void ExtractInterfaceMthod2()
        {

            var types = Assembly.Load("ClassLibrary1").GetTypes();
            StringBuilder sb = new StringBuilder();
            string str = "";
            string calfunc = "";
            Dictionary<string, ClassSummary> methodDictionary = new Dictionary<string, ClassSummary>();
            ClassSummary cs = null;
            foreach (var item in types)
            {



                if (item.Name == "User2EngineController")
                {

                    methodDictionary[item.Name] = new ClassSummary();
                    cs = methodDictionary[item.Name];
                    cs.ClassName = item.Name;
                    XmlDocument xmlDoc = new XmlDocument();
                    string configPath = AppDomain.CurrentDomain.BaseDirectory + @"ClassLibrary1.xml";
                    xmlDoc.Load(configPath);
                    XmlNode doc = xmlDoc.SelectSingleNode("doc");
                    XmlNode members = doc.SelectSingleNode("members");
                    XmlNodeList memberList = members.SelectNodes("member");
                    foreach (XmlNode member in memberList)
                    {
                        string summary = member.InnerXml;
                        string oriContent= member.SelectSingleNode("summary").InnerText.Replace("
", "").Replace("
","").Replace(" ","");
                        string content = "///" + oriContent;
         
                        string fullName = member.Attributes.GetNamedItem("name").InnerText.ToString();
                        string left = fullName.Split(()[0];
                        string methodName = left.Split(.)[left.Split(.).Length - 1];

                        cs.MethodSummaryDictionary[methodName] = summary.Replace(oriContent,content);


                    }
                    //载入xml文件名
                    var methods = item.GetMethods().ToList();

                    foreach (MethodInfo m in methods)
                    {
                        var returntype = m.ReturnType.Name;
                        string methodName = m.Name;
                        if (methodName == "ToString" || methodName == "GetHashCode" || methodName == "Equals" || methodName == "GetType")
                        {
                            continue;
                        }
                        if (string.Compare(returntype, "void", true) == 0)
                        {
                            returntype = "void";
                        }
                        str = $" {returntype} {methodName} ( ";
                        calfunc = $" {methodName} ( ";

                        var parameters = m.GetParameters().ToList();
                        foreach (ParameterInfo parameter in parameters)
                        {

                            string pn = parameter.Name;
                            string ptype = parameter.ParameterType.ToString();
                            bool isout = false;
                            if (ptype.EndsWith("&"))
                            {
                                isout = true;
                                ptype = $"out {ptype.TrimEnd(‘&‘)}";
                            }
                            str += ptype + " " + pn + ",";
                            if (isout)
                            {
                                pn = "out " + pn;
                            }
                            calfunc += pn + ",";
                        }
                        str = str.TrimEnd(,);
                        string isreturn = returntype != "void" ? "return" : "";
                        calfunc = calfunc.TrimEnd(,) + ");";

                        str += ");";
                        string summary = cs.MethodSummaryDictionary[m.Name];
                        summary = summary.Replace("<", "
<");
                        summary = summary.Replace("<", "///<");
                        sb.Append("
" + summary + "
" + str);

                    }


                }

            }
            var str1 = sb.ToString();
            Console.WriteLine(str1);
        }

    }
}

 

以上是关于summary的主要内容,如果未能解决你的问题,请参考以下文章

c# 排列组合代码类

微信小程序代码片段

VSCode自定义代码片段——CSS选择器

谷歌浏览器调试jsp 引入代码片段,如何调试代码片段中的js

片段和活动之间的核心区别是啥?哪些代码可以写成片段?

VSCode自定义代码片段——.vue文件的模板