Skip to content

Commit

Permalink
[修改]1. 修改服务器协议的代码格式
Browse files Browse the repository at this point in the history
  • Loading branch information
AlianBlank committed Feb 8, 2025
1 parent 53f741a commit a24a980
Showing 1 changed file with 42 additions and 33 deletions.
75 changes: 42 additions & 33 deletions ProtoExport/ProtoBuffServerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,74 +27,83 @@ public void Run(MessageInfoList messageInfoList, string outputPath, string names
{
if (operationCodeInfo.IsEnum)
{
sb.AppendLine($"\t/// <summary>");
sb.AppendLine($"\t/// {operationCodeInfo.Description}");
sb.AppendLine($"\t/// </summary>");
sb.AppendLine($"\t[System.ComponentModel.Description(\"{operationCodeInfo.Description}\")]");
sb.AppendLine($"\tpublic enum {operationCodeInfo.Name}");
sb.AppendLine("\t{");
foreach (var operationField in operationCodeInfo.Fields)
sb.AppendLine($" /// <summary>");
sb.AppendLine($" /// {operationCodeInfo.Description}");
sb.AppendLine($" /// </summary>");
sb.AppendLine($" [System.ComponentModel.Description(\"{operationCodeInfo.Description}\")]");
sb.AppendLine($" public enum {operationCodeInfo.Name}");
sb.AppendLine(" {");
for (var index = 0; index < operationCodeInfo.Fields.Count; index++)
{
sb.AppendLine($"\t\t/// <summary>");
sb.AppendLine($"\t\t/// {operationField.Description}");
sb.AppendLine($"\t\t/// </summary>");
sb.AppendLine($"\t\t[System.ComponentModel.Description(\"{operationField.Description}\")]");
sb.AppendLine($"\t\t{operationField.Type} = {operationField.Members},");
var operationField = operationCodeInfo.Fields[index];
sb.AppendLine($" /// <summary>");
sb.AppendLine($" /// {operationField.Description}");
sb.AppendLine($" /// </summary>");
sb.AppendLine($" [System.ComponentModel.Description(\"{operationField.Description}\")]");
sb.AppendLine($" {operationField.Type} = {operationField.Members},");
if (index < operationCodeInfo.Fields.Count - 1)
{
sb.AppendLine();
}
}

sb.AppendLine("\t}");
sb.AppendLine(" }");
sb.AppendLine();
}
else
{
sb.AppendLine($"\t/// <summary>");
sb.AppendLine($"\t/// {operationCodeInfo.Description}");
sb.AppendLine($"\t/// </summary>");
sb.AppendLine($"\t[ProtoContract]");
sb.AppendLine($"\t[System.ComponentModel.Description(\"{operationCodeInfo.Description}\")]");
sb.AppendLine($" /// <summary>");
sb.AppendLine($" /// {operationCodeInfo.Description}");
sb.AppendLine($" /// </summary>");
sb.AppendLine($" [ProtoContract]");
sb.AppendLine($" [System.ComponentModel.Description(\"{operationCodeInfo.Description}\")]");
if (string.IsNullOrEmpty(operationCodeInfo.ParentClass))
{
sb.AppendLine($"\tpublic sealed class {operationCodeInfo.Name}");
sb.AppendLine($" public sealed class {operationCodeInfo.Name}");
}
else
{
sb.AppendLine($"\t[MessageTypeHandler({(messageInfoList.Module << 16) + operationCodeInfo.Opcode})]");
sb.AppendLine($"\tpublic sealed class {operationCodeInfo.Name} : MessageObject, {operationCodeInfo.ParentClass}");
sb.AppendLine($" [MessageTypeHandler({(messageInfoList.Module << 16) + operationCodeInfo.Opcode})]");
sb.AppendLine($" public sealed class {operationCodeInfo.Name} : MessageObject, {operationCodeInfo.ParentClass}");
}

sb.AppendLine("\t{");
foreach (var operationField in operationCodeInfo.Fields)
sb.AppendLine(" {");
for (var index = 0; index < operationCodeInfo.Fields.Count; index++)
{
var operationField = operationCodeInfo.Fields[index];
if (!operationField.IsValid)
{
continue;
}

sb.AppendLine($"\t\t/// <summary>");
sb.AppendLine($"\t\t/// {operationField.Description}");
sb.AppendLine($"\t\t/// </summary>");
sb.AppendLine($"\t\t[ProtoMember({operationField.Members})]");
sb.AppendLine($"\t\t[System.ComponentModel.Description(\"{operationField.Description}\")]");
sb.AppendLine($" /// <summary>");
sb.AppendLine($" /// {operationField.Description}");
sb.AppendLine($" /// </summary>");
sb.AppendLine($" [ProtoMember({operationField.Members})]");
sb.AppendLine($" [System.ComponentModel.Description(\"{operationField.Description}\")]");
if (operationField.IsRepeated)
{
sb.AppendLine($"\t\tpublic List<{operationField.Type}> {operationField.Name} {{ get; set; }} = new List<{operationField.Type}>();");
sb.AppendLine($" public List<{operationField.Type}> {operationField.Name} {{ get; set; }} = new List<{operationField.Type}>();");
}
else
{
string defaultValue = string.Empty;
if (operationField.IsKv)
{
defaultValue = $" = new {operationField.Type}();";
sb.AppendLine($"\t\t[ProtoMap(DisableMap = true)]");
sb.AppendLine($" [ProtoMap(DisableMap = true)]");
}

sb.AppendLine($"\t\tpublic {operationField.Type} {operationField.Name} {{ get; set; }}{defaultValue}");
sb.AppendLine($" public {operationField.Type} {operationField.Name} {{ get; set; }}{defaultValue}");
}

sb.AppendLine();
if (index < operationCodeInfo.Fields.Count - 1)
{
sb.AppendLine();
}
}

sb.AppendLine("\t}");
sb.AppendLine(" }");
sb.AppendLine();
}
}
Expand Down

0 comments on commit a24a980

Please sign in to comment.