@@ -55,12 +55,14 @@ public TypeMetadataHelper(
55
55
/// <param name="oldType">The type metadata from the old (serialized) assembly.</param>
56
56
/// <param name="newType">The type metadata from the new assembly.</param>
57
57
/// <param name="issueLogger">ReportLogger that will keep track of issues found.</param>
58
- public void CompareTypeMetadata (
58
+ public bool CompareTypeMetadata (
59
59
CmdletMetadata cmdlet ,
60
60
TypeMetadata oldType ,
61
61
TypeMetadata newType ,
62
62
ReportLogger < BreakingChangeIssue > issueLogger )
63
63
{
64
+ var result = true ;
65
+
64
66
// For each property in the old assembly type, find the corresponding
65
67
// property in the new assembly type
66
68
foreach ( var oldProperty in oldType . Properties . Keys )
@@ -109,29 +111,33 @@ public void CompareTypeMetadata(
109
111
else
110
112
{
111
113
// If the type of the property has been changed, log an issue
112
- issueLogger . LogBreakingChangeIssue (
114
+ issueLogger ? . LogBreakingChangeIssue (
113
115
cmdlet : cmdlet ,
114
116
severity : 0 ,
115
117
problemId : ProblemIds . BreakingChangeProblemId . ChangedPropertyType ,
116
118
description : string . Format ( Properties . Resources . ChangedPropertyTypeDescription ,
117
119
oldProperty , oldType . Name , oldPropertyType , newPropertyType ) ,
118
120
remediation : string . Format ( Properties . Resources . ChangedPropertyTypeRemediation ,
119
121
oldProperty , oldPropertyType ) ) ;
122
+ result = false ;
120
123
}
121
124
}
122
125
else
123
126
{
124
127
// If the property has been removed, log an issue
125
- issueLogger . LogBreakingChangeIssue (
128
+ issueLogger ? . LogBreakingChangeIssue (
126
129
cmdlet : cmdlet ,
127
130
severity : 0 ,
128
131
problemId : ProblemIds . BreakingChangeProblemId . RemovedProperty ,
129
132
description : string . Format ( Properties . Resources . RemovedPropertyDescription ,
130
133
oldProperty , oldType . Name ) ,
131
134
remediation : string . Format ( Properties . Resources . RemovedPropertyRemediation ,
132
135
oldProperty , oldType . Name ) ) ;
136
+ result = false ;
133
137
}
134
138
}
139
+
140
+ return result ;
135
141
}
136
142
137
143
public void CompareMethodSignatures (
@@ -179,7 +185,7 @@ public void CompareMethodSignatures(
179
185
180
186
if ( ! found )
181
187
{
182
- issueLogger . LogBreakingChangeIssue (
188
+ issueLogger ? . LogBreakingChangeIssue (
183
189
cmdlet : cmdlet ,
184
190
severity : 0 ,
185
191
problemId : 0 ,
@@ -228,7 +234,7 @@ public void CheckParameterType(
228
234
// If the types are different, log an issue
229
235
if ( ! oldTypeMetadata . Name . Equals ( newTypeMetadata . Name , StringComparison . OrdinalIgnoreCase ) )
230
236
{
231
- issueLogger . LogBreakingChangeIssue (
237
+ issueLogger ? . LogBreakingChangeIssue (
232
238
cmdlet : cmdlet ,
233
239
severity : 0 ,
234
240
problemId : ProblemIds . BreakingChangeProblemId . ChangedParameterType ,
@@ -320,7 +326,7 @@ private bool IsElementType(
320
326
// If the element type has changed, log an issue
321
327
else
322
328
{
323
- issueLogger . LogBreakingChangeIssue (
329
+ issueLogger ? . LogBreakingChangeIssue (
324
330
cmdlet : cmdlet ,
325
331
severity : 0 ,
326
332
problemId : problemId ,
@@ -366,20 +372,34 @@ private bool IsGenericType(
366
372
var oldArgument = oldTypeMetadata . GenericTypeArguments [ idx ] ;
367
373
var newArgument = newTypeMetadata . GenericTypeArguments [ idx ] ;
368
374
369
- if ( CheckGenericTypeArguments ( cmdlet , oldArgument , newArgument , target , issueLogger ) )
375
+ var oldElementType = _oldTypeDictionary [ oldArgument ] ;
376
+ var newElementType = _newTypeDictionary [ newArgument ] ;
377
+ if ( string . Equals ( oldArgument , newArgument , StringComparison . OrdinalIgnoreCase ) )
370
378
{
371
379
// If we have not previously seen this generic type argument,
372
380
// run this method on the type
373
381
if ( ! _typeSet . Contains ( oldArgument ) )
374
382
{
375
383
_typeSet . Add ( oldArgument ) ;
376
-
377
- var oldElementType = _oldTypeDictionary [ oldArgument ] ;
378
- var newElementType = _newTypeDictionary [ newArgument ] ;
379
-
380
384
CompareTypeMetadata ( cmdlet , oldElementType , newElementType , issueLogger ) ;
381
385
}
382
386
}
387
+ else
388
+ {
389
+ // If the generic type arguments have changed, throw a specific exception for generics
390
+ if ( ! CompareTypeMetadata ( cmdlet , oldElementType , newElementType , issueLogger ) )
391
+ {
392
+ // If the generic type arguments aren't the same, log an issue
393
+ issueLogger ? . LogBreakingChangeIssue (
394
+ cmdlet : cmdlet ,
395
+ severity : 0 ,
396
+ problemId : ProblemIds . BreakingChangeProblemId . ChangedGenericTypeArgument ,
397
+ description : string . Format ( Properties . Resources . ChangedGenericTypeArgumentDescription ,
398
+ target , oldArgument , newArgument ) ,
399
+ remediation : string . Format ( Properties . Resources . ChangedGenericTypeArgumentRemediation ,
400
+ target , oldArgument ) ) ;
401
+ }
402
+ }
383
403
}
384
404
}
385
405
}
@@ -412,7 +432,7 @@ private bool HasSameGenericType(
412
432
}
413
433
414
434
// Otherwise, log an issue and return false
415
- issueLogger . LogBreakingChangeIssue (
435
+ issueLogger ? . LogBreakingChangeIssue (
416
436
cmdlet : cmdlet ,
417
437
severity : 0 ,
418
438
problemId : ProblemIds . BreakingChangeProblemId . ChangedGenericType ,
@@ -447,7 +467,7 @@ private bool HasSameGenericArgumentSize(
447
467
}
448
468
449
469
// Otherwise, log an issue and return false
450
- issueLogger . LogBreakingChangeIssue (
470
+ issueLogger ? . LogBreakingChangeIssue (
451
471
cmdlet : cmdlet ,
452
472
severity : 0 ,
453
473
problemId : ProblemIds . BreakingChangeProblemId . DifferentGenericTypeArgumentSize ,
@@ -459,38 +479,5 @@ private bool HasSameGenericArgumentSize(
459
479
460
480
return false ;
461
481
}
462
-
463
- /// <summary>
464
- /// Check if the arguments of a generic type are the same. If they are not, log an issue.
465
- /// </summary>
466
- /// <param name="cmdlet">The cmdlet metadata currently being checked.</param>
467
- /// <param name="oldArgument">The old argument from the generic.</param>
468
- /// <param name="newArgument">The new argument from the generic</param>
469
- /// <param name="target">Target of the generic type breaking change.</param>
470
- /// <param name="issueLogger">ReportLogger that will keep track of issues found.</param>
471
- private bool CheckGenericTypeArguments (
472
- CmdletMetadata cmdlet ,
473
- string oldArgument ,
474
- string newArgument ,
475
- string target ,
476
- ReportLogger < BreakingChangeIssue > issueLogger )
477
- {
478
- if ( oldArgument . Equals ( newArgument , StringComparison . OrdinalIgnoreCase ) )
479
- {
480
- return true ;
481
- }
482
-
483
- // If the generic type arguments aren't the same, log an issue
484
- issueLogger . LogBreakingChangeIssue (
485
- cmdlet : cmdlet ,
486
- severity : 0 ,
487
- problemId : ProblemIds . BreakingChangeProblemId . ChangedGenericTypeArgument ,
488
- description : string . Format ( Properties . Resources . ChangedGenericTypeArgumentDescription ,
489
- target , oldArgument , newArgument ) ,
490
- remediation : string . Format ( Properties . Resources . ChangedGenericTypeArgumentRemediation ,
491
- target , oldArgument ) ) ;
492
-
493
- return false ;
494
- }
495
482
}
496
483
}
0 commit comments