@@ -38,7 +38,8 @@ public UseLiteralInitializerForHashtable()
3838 {
3939 var presetTypeNames = new string [ ]
4040 {
41- "system.collection.hashtable" ,
41+ "system.collections.hashtable" ,
42+ "collections.hashtable" ,
4243 "hashtable"
4344 } ;
4445 presetTypeNameSet = new HashSet < string > ( presetTypeNames , StringComparer . OrdinalIgnoreCase ) ;
@@ -204,12 +205,11 @@ private void AnalyzeNewObjectCommand(CommandAst commandAst)
204205 return ;
205206 }
206207
207- if ( argumentList != null )
208+
209+ if ( argumentList != null
210+ && HasIgnoreCaseComparerArg ( argumentList ) )
208211 {
209- if ( argumentList . Any ( arg => arg != null && arg . EndsWith ( "ignorecase" , StringComparison . OrdinalIgnoreCase ) ) )
210- {
211- return ;
212- }
212+ return ;
213213 }
214214
215215 var dr = new DiagnosticRecord (
@@ -225,6 +225,9 @@ private void AnalyzeNewObjectCommand(CommandAst commandAst)
225225
226226 /// <summary>
227227 /// 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.
228231 /// </summary>
229232 /// <param name="commandAst">An non-null instance of CommandAst. Expects it be commandast of "new-object" command</param>
230233 /// <param name="typeName">Returns the TypeName argument</param>
@@ -356,9 +359,11 @@ private List<CommandElementAst> GetNamedArguments(ReadOnlyCollection<CommandElem
356359 /// <param name="arguments">A collection of argument asts. Neither this nor any elements within it should be null</param>
357360 private bool HasIgnoreCaseComparerArg ( ReadOnlyCollection < ExpressionAst > arguments )
358361 {
362+ var argumentsAsStrings = new List < string > ( ) ;
359363 foreach ( var arg in arguments )
360364 {
361365 var memberExprAst = arg as MemberExpressionAst ;
366+ argumentsAsStrings . Add ( null ) ;
362367 if ( memberExprAst == null )
363368 {
364369 continue ;
@@ -369,13 +374,30 @@ private bool HasIgnoreCaseComparerArg(ReadOnlyCollection<ExpressionAst> argument
369374 {
370375 continue ;
371376 }
377+ argumentsAsStrings [ argumentsAsStrings . Count - 1 ] = strConstExprAst . Value ;
378+ }
379+ return HasIgnoreCaseComparerArg ( argumentsAsStrings ) ;
380+ }
372381
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 ) )
374397 {
375398 return true ;
376399 }
377400 }
378-
379401 return false ;
380402 }
381403
0 commit comments