@@ -38,7 +38,8 @@ public UseLiteralInitializerForHashtable()
38
38
{
39
39
var presetTypeNames = new string [ ]
40
40
{
41
- "system.collection.hashtable" ,
41
+ "system.collections.hashtable" ,
42
+ "collections.hashtable" ,
42
43
"hashtable"
43
44
} ;
44
45
presetTypeNameSet = new HashSet < string > ( presetTypeNames , StringComparer . OrdinalIgnoreCase ) ;
@@ -204,12 +205,11 @@ private void AnalyzeNewObjectCommand(CommandAst commandAst)
204
205
return ;
205
206
}
206
207
207
- if ( argumentList != null )
208
+
209
+ if ( argumentList != null
210
+ && HasIgnoreCaseComparerArg ( argumentList ) )
208
211
{
209
- if ( argumentList . Any ( arg => arg != null && arg . EndsWith ( "ignorecase" , StringComparison . OrdinalIgnoreCase ) ) )
210
- {
211
- return ;
212
- }
212
+ return ;
213
213
}
214
214
215
215
var dr = new DiagnosticRecord (
@@ -225,6 +225,9 @@ private void AnalyzeNewObjectCommand(CommandAst commandAst)
225
225
226
226
/// <summary>
227
227
/// Interpret the named and unnamed arguments and assign them their corresponding parameters
228
+ ///
229
+ /// PSv4 onwards there exists System.Management.Automation.Language.StaticParameterBinder.BindCommand to
230
+ /// achieve identical objective. But since we support PSSA on PSv3 too we need this implementation.
228
231
/// </summary>
229
232
/// <param name="commandAst">An non-null instance of CommandAst. Expects it be commandast of "new-object" command</param>
230
233
/// <param name="typeName">Returns the TypeName argument</param>
@@ -356,9 +359,11 @@ private List<CommandElementAst> GetNamedArguments(ReadOnlyCollection<CommandElem
356
359
/// <param name="arguments">A collection of argument asts. Neither this nor any elements within it should be null</param>
357
360
private bool HasIgnoreCaseComparerArg ( ReadOnlyCollection < ExpressionAst > arguments )
358
361
{
362
+ var argumentsAsStrings = new List < string > ( ) ;
359
363
foreach ( var arg in arguments )
360
364
{
361
365
var memberExprAst = arg as MemberExpressionAst ;
366
+ argumentsAsStrings . Add ( null ) ;
362
367
if ( memberExprAst == null )
363
368
{
364
369
continue ;
@@ -369,13 +374,30 @@ private bool HasIgnoreCaseComparerArg(ReadOnlyCollection<ExpressionAst> argument
369
374
{
370
375
continue ;
371
376
}
377
+ argumentsAsStrings [ argumentsAsStrings . Count - 1 ] = strConstExprAst . Value ;
378
+ }
379
+ return HasIgnoreCaseComparerArg ( argumentsAsStrings ) ;
380
+ }
372
381
373
- if ( strConstExprAst . Value . EndsWith ( "ignorecase" ) )
382
+ /// <summary>
383
+ /// Checks if any argument in the given collection ends with "ignorecase"
384
+ /// </summary>
385
+ /// <param name="arguments">An enumerable of type string. Elements can be null but the collection must be non-null .</param>
386
+ /// <returns></returns>
387
+ private bool HasIgnoreCaseComparerArg ( IEnumerable < string > arguments )
388
+ {
389
+
390
+ foreach ( var arg in arguments )
391
+ {
392
+ if ( arg == null )
393
+ {
394
+ continue ;
395
+ }
396
+ if ( arg . EndsWith ( "ignorecase" , StringComparison . OrdinalIgnoreCase ) )
374
397
{
375
398
return true ;
376
399
}
377
400
}
378
-
379
401
return false ;
380
402
}
381
403
0 commit comments