@@ -52,14 +52,15 @@ public static MessageInfoList Parse(string proto, string fileName, string filePa
52
52
throw new Exception ( "Module not found==>example: option module = 100" ) ;
53
53
}
54
54
55
- Console . WriteLine ( $ "Package: { packageMatch . Groups [ 1 ] . Value } => Module: { moduleMatch . Groups [ 1 ] . Value } ") ;
55
+ var packageName = packageMatch . Groups [ 1 ] . Value ;
56
+ Console . WriteLine ( $ "Package: { packageName } => Module: { moduleMatch . Groups [ 1 ] . Value } ") ;
56
57
// 使用正则表达式提取枚举类型
57
- ParseEnum ( proto , messageInfo . Infos ) ;
58
+ ParseEnum ( proto , packageName , messageInfo . Infos ) ;
58
59
59
60
// 使用正则表达式提取消息类型
60
- ParseMessage ( proto , messageInfo . Infos , isGenerateErrorCode ) ;
61
+ ParseMessage ( proto , packageName , messageInfo . Infos , isGenerateErrorCode ) ;
61
62
62
- ParseComment ( proto , messageInfo . Infos ) ;
63
+ ParseComment ( proto , packageName , messageInfo . Infos ) ;
63
64
64
65
// 消息码排序配对
65
66
MessageIdHandler ( messageInfo . Infos , 10 ) ;
@@ -92,7 +93,7 @@ private static void MessageIdHandler(List<MessageInfo> operationCodeInfos, int s
92
93
}
93
94
}
94
95
95
- private static void ParseComment ( string proto , List < MessageInfo > operationCodeInfos )
96
+ private static void ParseComment ( string proto , string packageName , List < MessageInfo > operationCodeInfos )
96
97
{
97
98
MatchCollection enumMatches = Regex . Matches ( proto , CommentPattern , RegexOptions . Singleline ) ;
98
99
foreach ( Match match in enumMatches )
@@ -113,14 +114,19 @@ private static void ParseComment(string proto, List<MessageInfo> operationCodeIn
113
114
}
114
115
}
115
116
116
- private static void ParseEnum ( string proto , List < MessageInfo > codes )
117
+ private static void ParseEnum ( string proto , string packageName , List < MessageInfo > codes )
117
118
{
118
119
MatchCollection enumMatches = Regex . Matches ( proto , EnumPattern , RegexOptions . Singleline ) ;
119
120
foreach ( Match match in enumMatches )
120
121
{
121
122
MessageInfo info = new MessageInfo ( true ) ;
122
123
codes . Add ( info ) ;
123
124
string blockName = match . Groups [ 1 ] . Value ;
125
+ if ( ! Utility . IsCamelCase ( blockName ) )
126
+ {
127
+ throw new Exception ( $ "[{ packageName } ] 包的 [{ blockName } ] 枚举名称必须遵守 [Upper Camel Case 命名规则]\n ") ;
128
+ }
129
+
124
130
info . Name = blockName ;
125
131
// Console.WriteLine("Enum Name: " + match.Groups[1].Value);
126
132
// Console.WriteLine("Contents: " + match.Groups[2].Value);
@@ -143,25 +149,34 @@ private static void ParseEnum(string proto, List<MessageInfo> codes)
143
149
var fieldSplit = fieldType . Split ( '=' , StringSplitOptions . RemoveEmptyEntries ) ;
144
150
if ( fieldSplit . Length > 1 )
145
151
{
146
- field . Type = fieldSplit [ 0 ] . Trim ( ) ;
152
+ var name = fieldSplit [ 0 ] . Trim ( ) ;
153
+ if ( ! Utility . IsCamelCase ( name ) )
154
+ {
155
+ throw new Exception ( $ "[{ packageName } ] 包的 { name } 枚举字段名称必须遵守 [Upper Camel Case 命名规则]\n ") ;
156
+ }
157
+
158
+ field . Type = name ;
147
159
field . Members = int . Parse ( fieldSplit [ 1 ] . Replace ( ";" , "" ) . Trim ( ) ) ;
148
160
}
149
161
}
150
162
}
151
163
}
152
164
}
153
165
154
- private static void ParseMessage ( string proto , List < MessageInfo > codes , bool isGenerateErrorCode = false )
166
+ private static void ParseMessage ( string proto , string packageName , List < MessageInfo > codes , bool isGenerateErrorCode = false )
155
167
{
156
168
MatchCollection messageMatches = Regex . Matches ( proto , MessagePattern , RegexOptions . Singleline ) ;
157
169
foreach ( Match match in messageMatches )
158
170
{
159
171
string messageName = match . Groups [ 1 ] . Value ;
160
- // Console.WriteLine("Message Name: " + match.Groups[1].Value);
161
- // Console.WriteLine("Contents: " + match.Groups[2].Value);
162
172
var blockContent = match . Groups [ 2 ] . Value . Trim ( ) ;
163
173
MessageInfo info = new MessageInfo ( ) ;
164
174
codes . Add ( info ) ;
175
+ if ( ! Utility . IsCamelCase ( messageName ) )
176
+ {
177
+ throw new Exception ( $ "[{ packageName } ] 包的 [{ messageName } ] 消息名称必须遵守 [Upper Camel Case 命名规则]\n ") ;
178
+ }
179
+
165
180
info . Name = messageName ;
166
181
foreach ( var line in blockContent . Split ( new string [ ] { "\r " , "\n " , "\r \n " } , StringSplitOptions . RemoveEmptyEntries ) )
167
182
{
@@ -204,13 +219,25 @@ private static void ParseMessage(string proto, List<MessageInfo> codes, bool isG
204
219
}
205
220
}
206
221
222
+ var name = fieldSplitStrings [ 2 ] . Trim ( ) ;
223
+
224
+ if ( ! Utility . IsCamelCase ( name ) )
225
+ {
226
+ throw new Exception ( $ "[{ packageName } ] 包的 [{ messageName } ] 消息的 [{ name } ] 字段名称必须遵守 [Upper Camel Case 命名规则]\n ") ;
227
+ }
207
228
208
- field . Name = fieldSplitStrings [ 2 ] . Trim ( ) ;
229
+ field . Name = name ;
209
230
}
210
231
else if ( fieldSplitStrings . Length > 1 )
211
232
{
212
233
field . Type = Utility . ConvertType ( fieldSplitStrings [ 0 ] . Trim ( ) ) ;
213
- field . Name = fieldSplitStrings [ 1 ] . Trim ( ) ;
234
+ var name = fieldSplitStrings [ 1 ] . Trim ( ) ;
235
+ if ( ! Utility . IsCamelCase ( name ) )
236
+ {
237
+ throw new Exception ( $ "[{ packageName } ] 包的 [{ messageName } ] 消息的 [{ name } ] 字段名称必须遵守 [Upper Camel Case 命名规则]\n ") ;
238
+ }
239
+
240
+ field . Name = name ;
214
241
}
215
242
}
216
243
}
@@ -227,7 +254,4 @@ private static void ParseMessage(string proto, List<MessageInfo> codes, bool isG
227
254
}
228
255
}
229
256
}
230
-
231
- [ GeneratedRegex ( ModulePattern , RegexOptions . Singleline ) ]
232
- private static partial Regex MyRegex ( ) ;
233
257
}
0 commit comments