コード例 #1
0
ファイル: MainForm.cs プロジェクト: zanderzhg/JHRS
        /// <summary>
        /// 生成方法
        /// </summary>
        /// <param name="model">方法类</param>
        /// <returns></returns>
        private string GenerationMethod(CollectInterfaceClass model)
        {
            StringBuilder sb = new StringBuilder(2000);

            foreach (var item in model.Methods)
            {
                string pars = "";

                sb.Append("        /// <summary>\r\n");
                sb.AppendFormat("        /// {0}\r\n", item.Description);
                sb.Append("        /// </summary>\r\n");

                if (item.ParameterName.Length > 0)
                {
                    for (int i = 0; i < item.ParameterName.Length; i++)
                    {
                        sb.AppendFormat("        /// <param name=\"{0}\">{1}</param>\r\n", item.ParameterName[i], item.ParameterDes[i]);

                        pars += $"{item.ParameterType[i]} {item.ParameterName[i]}, ";
                    }
                    pars = pars.TrimEnd(", ".ToArray());
                }
                sb.AppendFormat("        /// <returns>见返回参数</returns>\r\n");
                sb.AppendFormat("        [{0}(\"{1}\")]\r\n", item.MethodType.Replace("p", "P").Replace("g", "G"), item.Api);
                sb.AppendFormat("        Task<{0}> {1}({2});\r\n\r\n", item.Return, item.Name, pars);
            }

            return(sb.ToString().TrimEnd("\r\n\r\n".ToArray()));
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: zanderzhg/JHRS
        /// <summary>
        /// 解析每个接口对应方法
        /// </summary>
        /// <param name="belong">当前隶属类</param>
        /// <param name="data">原始json</param>
        /// <param name="module">当前模块</param>
        /// <param name="methods">方法</param>
        private void FindMethods(CollectInterfaceClass belong, JObject data, string module, JToken[] methods)
        {
            var m = new List <Method>();

            foreach (var item in methods)
            {
                var api = (item as JProperty).Name;
                var(parsName, parsType, parsDes) = GetParameter(item);

                var first = (item.ElementAt(0).ElementAt(0) as JProperty).Name;
                m.Add(new Method
                {
                    Api           = api,
                    Description   = (item.ElementAt(0).SelectToken($"{first}.summary") + "").Replace(Environment.NewLine, ""),
                    MethodType    = first,
                    Name          = api.Substring(api.LastIndexOf('/') + 1),
                    ParameterName = parsName,
                    ParameterType = parsType,
                    ParameterDes  = parsDes,
                    Return        = FindReturn(item)
                });
            }
            belong.Methods = m;
        }