Skip to content

Commit fbf4f6c

Browse files
iSazonovadityapatwardhan
authored andcommitted
Replace ArrayList with List<T> (PowerShell#10333)
1 parent f6c220c commit fbf4f6c

File tree

14 files changed

+59
-62
lines changed

14 files changed

+59
-62
lines changed

src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -338,13 +338,9 @@ private bool ScanForwardsForTail(ContentHolder holder, CmdletProviderContext cur
338338
if (ReadCount <= 0 || (ReadCount >= tailResultQueue.Count && ReadCount != 1))
339339
{
340340
count = tailResultQueue.Count;
341-
ArrayList outputList = new ArrayList();
342-
while (tailResultQueue.Count > 0)
343-
{
344-
outputList.Add(tailResultQueue.Dequeue());
345-
}
341+
346342
// Write out the content as an array of objects
347-
WriteContentObject(outputList.ToArray(), count, holder.PathInfo, currentContext);
343+
WriteContentObject(tailResultQueue.ToArray(), count, holder.PathInfo, currentContext);
348344
}
349345
else if (ReadCount == 1)
350346
{
@@ -356,7 +352,7 @@ private bool ScanForwardsForTail(ContentHolder holder, CmdletProviderContext cur
356352
{
357353
while (tailResultQueue.Count >= ReadCount)
358354
{
359-
ArrayList outputList = new ArrayList();
355+
var outputList = new List<object>((int)ReadCount);
360356
for (int idx = 0; idx < ReadCount; idx++, count++)
361357
outputList.Add(tailResultQueue.Dequeue());
362358
// Write out the content as an array of objects
@@ -366,11 +362,8 @@ private bool ScanForwardsForTail(ContentHolder holder, CmdletProviderContext cur
366362
int remainder = tailResultQueue.Count;
367363
if (remainder > 0)
368364
{
369-
ArrayList outputList = new ArrayList();
370-
for (; remainder > 0; remainder--, count++)
371-
outputList.Add(tailResultQueue.Dequeue());
372365
// Write out the content as an array of objects
373-
WriteContentObject(outputList.ToArray(), count, holder.PathInfo, currentContext);
366+
WriteContentObject(tailResultQueue.ToArray(), count, holder.PathInfo, currentContext);
374367
}
375368
}
376369
}

src/Microsoft.PowerShell.Commands.Management/commands/management/WriteContentCommandBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ private string[] GetAcceptedPaths(string[] unfilteredPaths, CmdletProviderContex
333333
{
334334
Collection<PathInfo> pathInfos = ResolvePaths(unfilteredPaths, true, false, currentContext);
335335

336-
ArrayList paths = new ArrayList();
336+
var paths = new List<string>();
337337

338338
foreach (PathInfo pathInfo in pathInfos)
339339
{
@@ -343,7 +343,7 @@ private string[] GetAcceptedPaths(string[] unfilteredPaths, CmdletProviderContex
343343
}
344344
}
345345

346-
return (string[])paths.ToArray(typeof(string));
346+
return paths.ToArray();
347347
}
348348

349349
#endregion protected members

src/Microsoft.PowerShell.Commands.Utility/commands/utility/ConvertTo-Html.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ private List<MshParameter> ProcessParameter(object[] properties)
359359
private void InitializeResolvedNameMshParameters()
360360
{
361361
// temp list of properties with wildcards resolved
362-
ArrayList resolvedNameProperty = new ArrayList();
362+
var resolvedNameProperty = new List<object>();
363363

364364
foreach (MshParameter p in _propertyMshParameterList)
365365
{

src/Microsoft.PowerShell.Commands.Utility/commands/utility/Var.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ protected override void ProcessRecord()
747747
{
748748
if (_valueList == null)
749749
{
750-
_valueList = new ArrayList();
750+
_valueList = new List<object>();
751751
}
752752

753753
_valueList.Add(Value);
@@ -759,7 +759,7 @@ protected override void ProcessRecord()
759759
}
760760
}
761761

762-
private ArrayList _valueList;
762+
private List<object> _valueList;
763763

764764
/// <summary>
765765
/// Sets the variable if the name was specified as a formal parameter

src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2670,7 +2670,7 @@ private void EvaluateSuggestions(ConsoleHostUserInterface ui)
26702670
// Output any training suggestions
26712671
try
26722672
{
2673-
ArrayList suggestions = HostUtilities.GetSuggestion(_parent.Runspace);
2673+
List<string> suggestions = HostUtilities.GetSuggestion(_parent.Runspace);
26742674

26752675
if (suggestions.Count > 0)
26762676
{

src/Microsoft.PowerShell.Security/security/CertificateCommands.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public string[] LiteralPath
8080
//
8181
// list of files that were not found
8282
//
83-
private ArrayList _filesNotFound = new ArrayList();
83+
private List<string> _filesNotFound = new List<string>();
8484

8585
/// <summary>
8686
/// Initializes a new instance of the GetPfxCertificateCommand

src/System.Management.Automation/FormatAndOutput/out-console/OutConsole.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the MIT License.
33

44
using System;
5-
using System.Collections;
5+
using System.Collections.Generic;
66
using System.Management.Automation;
77
using System.Management.Automation.Host;
88
using System.Management.Automation.Internal;
@@ -88,7 +88,7 @@ protected override void BeginProcessing()
8888

8989
if (Context.CurrentCommandProcessor.CommandRuntime.OutVarList != null)
9090
{
91-
_outVarResults = new ArrayList();
91+
_outVarResults = new List<PSObject>();
9292
}
9393
}
9494

@@ -162,7 +162,7 @@ protected override void InternalDispose()
162162
}
163163
}
164164

165-
private ArrayList _outVarResults = null;
165+
private List<PSObject> _outVarResults = null;
166166
private IDisposable _transcribeOnlyCookie = null;
167167
}
168168

src/System.Management.Automation/engine/hostifaces/HostUtilities.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ public static class HostUtilities
7272
$formatString -f [string]::Join(', ', (Get-Command $lastError.TargetObject -UseFuzzyMatch | Select-Object -First 10 -Unique -ExpandProperty Name))
7373
";
7474

75-
private static ArrayList s_suggestions = InitializeSuggestions();
75+
private static List<Hashtable> s_suggestions = InitializeSuggestions();
7676

77-
private static ArrayList InitializeSuggestions()
77+
private static List<Hashtable> InitializeSuggestions()
7878
{
79-
ArrayList suggestions = new ArrayList(
79+
var suggestions = new List<Hashtable>(
8080
new Hashtable[]
8181
{
8282
NewSuggestion(
@@ -307,10 +307,10 @@ internal static string GetMaxLines(string source, int maxLines)
307307
return returnValue.ToString();
308308
}
309309

310-
internal static ArrayList GetSuggestion(Runspace runspace)
310+
internal static List<string> GetSuggestion(Runspace runspace)
311311
{
312312
LocalRunspace localRunspace = runspace as LocalRunspace;
313-
if (localRunspace == null) { return new ArrayList(); }
313+
if (localRunspace == null) { return new List<string>(); }
314314

315315
// Get the last value of $?
316316
bool questionMarkVariableValue = localRunspace.ExecutionContext.QuestionMarkVariableValue;
@@ -320,7 +320,7 @@ internal static ArrayList GetSuggestion(Runspace runspace)
320320
HistoryInfo[] entries = history.GetEntries(-1, 1, true);
321321

322322
if (entries.Length == 0)
323-
return new ArrayList();
323+
return new List<string>();
324324

325325
HistoryInfo lastHistory = entries[0];
326326

@@ -363,7 +363,7 @@ internal static ArrayList GetSuggestion(Runspace runspace)
363363
Runspace.DefaultRunspace = runspace;
364364
}
365365

366-
ArrayList suggestions = null;
366+
List<string> suggestions = null;
367367

368368
try
369369
{
@@ -383,9 +383,9 @@ internal static ArrayList GetSuggestion(Runspace runspace)
383383
}
384384

385385
[SuppressMessage("Microsoft.Usage", "CA2208:InstantiateArgumentExceptionsCorrectly")]
386-
internal static ArrayList GetSuggestion(HistoryInfo lastHistory, object lastError, ArrayList errorList)
386+
internal static List<string> GetSuggestion(HistoryInfo lastHistory, object lastError, ArrayList errorList)
387387
{
388-
ArrayList returnSuggestions = new ArrayList();
388+
var returnSuggestions = new List<string>();
389389

390390
PSModuleInfo invocationModule = new PSModuleInfo(true);
391391
invocationModule.SessionState.PSVariable.Set("lastHistory", lastHistory);

src/System.Management.Automation/engine/remoting/client/remoterunspace.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ internal class RemoteRunspace : Runspace, IDisposable
3232
{
3333
#region Private Members
3434

35-
private ArrayList _runningPipelines = new ArrayList();
35+
private List<RemotePipeline> _runningPipelines = new List<RemotePipeline>();
3636
private object _syncRoot = new object();
3737
private RunspaceStateInfo _runspaceStateInfo = new RunspaceStateInfo(RunspaceState.BeforeOpen);
3838
private bool _bSessionStateProxyCallInProgress = false;
@@ -1522,7 +1522,7 @@ private bool WaitForFinishofPipelines()
15221522

15231523
lock (_syncRoot)
15241524
{
1525-
runningPipelines = (RemotePipeline[])_runningPipelines.ToArray(typeof(RemotePipeline));
1525+
runningPipelines = _runningPipelines.ToArray();
15261526
}
15271527

15281528
if (runningPipelines.Length > 0)

src/System.Management.Automation/engine/remoting/common/WireDataFormat/EncodeAndDecode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1912,7 +1912,7 @@ internal static PSEventArgs GetPSEventArgs(PSObject dataAsPSObject)
19121912
string computerName = GetPropertyValue<string>(dataAsPSObject, RemoteDataNameStrings.PSEventArgsComputerName);
19131913
Guid runspaceId = GetPropertyValue<Guid>(dataAsPSObject, RemoteDataNameStrings.PSEventArgsRunspaceId);
19141914

1915-
ArrayList sourceArgs = new ArrayList();
1915+
var sourceArgs = new List<object>();
19161916
foreach (object argument in RemotingDecoder.EnumerateListProperty<object>(dataAsPSObject, RemoteDataNameStrings.PSEventArgsSourceArgs))
19171917
{
19181918
sourceArgs.Add(argument);

0 commit comments

Comments
 (0)