@@ -54,6 +54,10 @@ internal void ValidateIdentifiers(CodeObject e)
54
54
{
55
55
ValidateCodeDirective ( ( CodeDirective ) e ) ;
56
56
}
57
+ else if ( e == null )
58
+ {
59
+ throw new ArgumentNullException ( nameof ( e ) ) ;
60
+ }
57
61
else
58
62
{
59
63
throw new ArgumentException ( SR . Format ( SR . InvalidElementType , e . GetType ( ) . FullName ) , nameof ( e ) ) ;
@@ -159,7 +163,11 @@ private void ValidateNamespaceImports(CodeNamespace e)
159
163
{
160
164
foreach ( CodeNamespaceImport imp in e . Imports )
161
165
{
162
- if ( imp . LinePragma != null ) ValidateLinePragmaStart ( imp . LinePragma ) ;
166
+ if ( imp . LinePragma != null )
167
+ {
168
+ ValidateLinePragmaStart ( imp . LinePragma ) ;
169
+ }
170
+
163
171
ValidateNamespaceImport ( imp ) ;
164
172
}
165
173
}
@@ -395,9 +403,8 @@ private void ValidateTypeStart(CodeTypeDeclaration e)
395
403
}
396
404
397
405
ValidateIdentifier ( e , nameof ( e . Name ) , e . Name ) ;
398
- if ( IsCurrentDelegate )
406
+ if ( e is CodeTypeDelegate del )
399
407
{
400
- CodeTypeDelegate del = ( CodeTypeDelegate ) e ;
401
408
ValidateTypeReference ( del . ReturnType ) ;
402
409
ValidateParameters ( del . Parameters ) ;
403
410
}
@@ -429,6 +436,11 @@ private void ValidateComment(CodeComment e)
429
436
430
437
private void ValidateStatement ( CodeStatement e )
431
438
{
439
+ if ( e == null )
440
+ {
441
+ throw new ArgumentNullException ( nameof ( e ) ) ;
442
+ }
443
+
432
444
ValidateCodeDirectives ( e . StartDirectives ) ;
433
445
ValidateCodeDirectives ( e . EndDirectives ) ;
434
446
@@ -684,7 +696,7 @@ private static void ValidateArity(CodeTypeReference e)
684
696
// Check if we have zero type args for open types.
685
697
if ( ( totalTypeArgs != e . TypeArguments . Count ) && ( e . TypeArguments . Count != 0 ) )
686
698
{
687
- throw new ArgumentException ( SR . Format ( SR . ArityDoesntMatch , baseType , e . TypeArguments . Count ) ) ;
699
+ throw new ArgumentException ( SR . Format ( SR . ArityDoesntMatch , baseType , e . TypeArguments . Count ) , nameof ( e ) ) ;
688
700
}
689
701
}
690
702
@@ -693,7 +705,7 @@ private static void ValidateTypeName(object e, string propertyName, string typeN
693
705
if ( ! CodeGenerator . IsValidLanguageIndependentTypeName ( typeName ) )
694
706
{
695
707
string message = SR . Format ( SR . InvalidTypeName , typeName , propertyName , e . GetType ( ) . FullName ) ;
696
- throw new ArgumentException ( message , nameof ( typeName ) ) ;
708
+ throw new ArgumentException ( message , nameof ( e ) ) ;
697
709
}
698
710
}
699
711
@@ -702,7 +714,7 @@ private static void ValidateIdentifier(object e, string propertyName, string ide
702
714
if ( ! CodeGenerator . IsValidLanguageIndependentIdentifier ( identifier ) )
703
715
{
704
716
string message = SR . Format ( SR . InvalidLanguageIdentifier , identifier , propertyName , e . GetType ( ) . FullName ) ;
705
- throw new ArgumentException ( message , nameof ( identifier ) ) ;
717
+ throw new ArgumentException ( message , nameof ( e ) ) ;
706
718
}
707
719
}
708
720
@@ -1014,19 +1026,17 @@ private static void ValidateCodeDirective(CodeDirective e)
1014
1026
private static void ValidateChecksumPragma ( CodeChecksumPragma e )
1015
1027
{
1016
1028
if ( e . FileName . IndexOfAny ( Path . GetInvalidPathChars ( ) ) != - 1 )
1017
- throw new ArgumentException ( SR . Format ( SR . InvalidPathCharsInChecksum , e . FileName ) ) ;
1029
+ throw new ArgumentException ( SR . Format ( SR . InvalidPathCharsInChecksum , e . FileName ) , nameof ( e ) ) ;
1018
1030
}
1019
1031
1020
1032
private static void ValidateRegionDirective ( CodeRegionDirective e )
1021
1033
{
1022
1034
if ( e . RegionText . IndexOfAny ( s_newLineChars ) != - 1 )
1023
- throw new ArgumentException ( SR . Format ( SR . InvalidRegion , e . RegionText ) ) ;
1035
+ throw new ArgumentException ( SR . Format ( SR . InvalidRegion , e . RegionText ) , nameof ( e ) ) ;
1024
1036
}
1025
1037
1026
1038
private bool IsCurrentInterface => _currentClass != null && ! ( _currentClass is CodeTypeDelegate ) ? _currentClass . IsInterface : false ;
1027
1039
1028
1040
private bool IsCurrentEnum => _currentClass != null && ! ( _currentClass is CodeTypeDelegate ) ? _currentClass . IsEnum : false ;
1029
-
1030
- private bool IsCurrentDelegate => _currentClass != null && _currentClass is CodeTypeDelegate ;
1031
1041
}
1032
1042
}
0 commit comments