Skip to content

Commit 91fc8c3

Browse files
committed
feat(ProtoBuffServerHelper): 为操作码信息添加Clear方法实现
当操作码信息有父类时,自动生成Clear方法用于清空字段值。对于重复字段和键值对字段使用Clear(),其他字段设置为默认值。
1 parent 1e43664 commit 91fc8c3

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

ProtoExport/ProtoBuffServerHelper.cs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,40 @@ public void Run(MessageInfoList messageInfoList, string outputPath, string names
107107
}
108108
}
109109

110-
sb.AppendLine(" }");
110+
if (!string.IsNullOrEmpty(operationCodeInfo.ParentClass))
111+
{
112+
sb.AppendLine();
113+
sb.AppendLine("\t\tpublic override void Clear()");
114+
sb.AppendLine("\t\t{");
115+
for (var index = 0; index < operationCodeInfo.Fields.Count; index++)
116+
{
117+
var operationField = operationCodeInfo.Fields[index];
118+
if (!operationField.IsValid)
119+
{
120+
continue;
121+
}
122+
123+
if (operationField.IsRepeated)
124+
{
125+
sb.AppendLine($"\t\t\t{operationField.Name}.Clear();");
126+
}
127+
else
128+
{
129+
if (operationField.IsKv)
130+
{
131+
sb.AppendLine($"\t\t\t{operationField.Name}.Clear();");
132+
}
133+
else
134+
{
135+
sb.AppendLine($"\t\t\t{operationField.Name} = default;");
136+
}
137+
}
138+
}
139+
140+
sb.AppendLine("\t\t}");
141+
}
142+
143+
sb.AppendLine("\t}");
111144
sb.AppendLine();
112145
}
113146
}

0 commit comments

Comments
 (0)