示例#1
0
    private static string GenerateFunCode(ProtoMessageData data)
    {
        TemplateSystem template = new TemplateSystem(tplAction);

        template.AddVariable("cnname", data.cnname);
        template.AddVariable("funName", data.name);
        template.AddVariable("msgType", data.resFullName);
        string content = template.Parse();

        return(content);
    }
    private static string GenerateFunCode(ProtoMessageData data)
    {
        List <string>   note = new List <string>();
        List <string>   args = new List <string>();
        List <object[]> list = new List <object[]>();

        note.Add("/**");
        note.Add($"         * {data.cnname}");


        int index = 0;
        int count = data.req.fields.Count;

        foreach (var kvp in data.req.fields)
        {
            // 0 fieldName
            // 1 fieldType
            // 2 ,或者空
            // 3 注释

            FieldData field = kvp.Value;

            list.Add(new object[] { field.fieldName, field.tsType, index >= count - 1 ? string.Empty : ",", field.cnname });
            args.Add($"{field.fieldName}: {field.tsType}");
            note.Add($"		 * @param {field.fieldName}  {field.cnname}");
            index++;
        }

        note.Add("         */");


        TemplateSystem template = new TemplateSystem(tplAction);

        template.AddVariable("cnname", data.cnname);
        template.AddVariable("funName", data.name);
        template.AddVariable("fullClassName", data.reqFullName);
        template.AddVariable("args", String.Join(", ", args));
        template.AddVariable("note", String.Join("\n", note));

        template.AddVariable("list", list.ToArray());
        string content = template.Parse();

        return(content);
    }
示例#3
0
    private void Read(string path)
    {
        Console.WriteLine(path);
        string   jsonTxt  = File.ReadAllText(path);
        JsonData jsonData = JsonMapper.ToObject(jsonTxt);

        foreach (var key in jsonData.Keys)
        {
            ProtoModuleData module = new ProtoModuleData();
            module.name = key;
            this.modules.Add(module.name, module);


            JsonData jModule = jsonData[key];

            foreach (var mKey in jModule.Keys)
            {
                ProtoMessageData msg = new ProtoMessageData();
                msg.name = mKey;
                module.AddMsg(msg);
                JsonData jMsg = jModule[mKey];
                JsonData jReq = jMsg["<req>"];
                JsonData jRes = jMsg["<res>"];

                foreach (var fieldKey in jReq.Keys)
                {
                    string fieldName = fieldKey.ToString();
                    msg.req.Add(fieldName, jReq[fieldName].ToString());
                }

                foreach (var fieldKey in jRes.Keys)
                {
                    string fieldName = fieldKey.ToString();
                    msg.res.Add(fieldName, jRes[fieldName].ToString());
                }
            }
        }


        ReadNote(jsonTxt);
    }
 public void AddMsg(ProtoMessageData msg)
 {
     msg.module = this;
     msgs.Add(msg.name, msg);
 }