File tree Expand file tree Collapse file tree 1 file changed +7
-18
lines changed
csharp/src/Google.Protobuf/Reflection Expand file tree Collapse file tree 1 file changed +7
-18
lines changed Original file line number Diff line number Diff line change @@ -187,35 +187,24 @@ private static void ValidateSymbolName(IDescriptor descriptor)
187
187
throw new DescriptorValidationException ( descriptor , "Missing name." ) ;
188
188
}
189
189
190
- if ( ! IsValidSymbolNameFormat ( descriptor . Name ) )
191
- {
192
- throw new DescriptorValidationException ( descriptor ,
193
- "\" " + descriptor . Name + "\" is not a valid identifier." ) ;
194
- }
195
- }
196
-
197
- /// <summary>
198
- /// Symbol name must start with a letter or underscore, and it can contain letters, numbers and underscores.
199
- /// </summary>
200
- private static bool IsValidSymbolNameFormat ( string name )
201
- {
190
+ // Symbol name must start with a letter or underscore, and it can contain letters, numbers and underscores.
191
+ string name = descriptor . Name ;
202
192
if ( ! IsAsciiLetter ( name [ 0 ] ) && name [ 0 ] != '_' )
203
193
{
204
- return false ;
194
+ ThrowInvalidSymbolNameException ( descriptor ) ;
205
195
}
206
-
207
196
for ( int i = 1 ; i < name . Length ; i ++ )
208
197
{
209
198
if ( ! IsAsciiLetter ( name [ i ] ) && ! IsAsciiDigit ( name [ i ] ) && name [ i ] != '_' )
210
199
{
211
- return false ;
200
+ ThrowInvalidSymbolNameException ( descriptor ) ;
212
201
}
213
202
}
214
203
215
- return true ;
216
-
217
204
static bool IsAsciiLetter ( char c ) => ( uint ) ( ( c | 0x20 ) - 'a' ) <= 'z' - 'a' ;
218
- static bool IsAsciiDigit ( char c ) => ( uint ) ( c - '0' ) <= ( '9' - '0' ) ;
205
+ static bool IsAsciiDigit ( char c ) => ( uint ) ( c - '0' ) <= '9' - '0' ;
206
+ static void ThrowInvalidSymbolNameException ( IDescriptor descriptor ) =>
207
+ throw new DescriptorValidationException ( descriptor , "\" " + descriptor . Name + "\" is not a valid identifier." ) ;
219
208
}
220
209
221
210
/// <summary>
You can’t perform that action at this time.
0 commit comments