diff --git a/src/Microsoft.PowerShell.Commands.Diagnostics/GetCounterCommand.cs b/src/Microsoft.PowerShell.Commands.Diagnostics/GetCounterCommand.cs index 459d553e27a..60608046811 100644 --- a/src/Microsoft.PowerShell.Commands.Diagnostics/GetCounterCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Diagnostics/GetCounterCommand.cs @@ -5,7 +5,6 @@ using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Collections.Specialized; using System.ComponentModel; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; @@ -317,7 +316,7 @@ private void ProcessListSet() // private void ProcessListSetPerMachine(string machine) { - StringCollection counterSets = new StringCollection(); + List counterSets = new List(); uint res = _pdhHelper.EnumObjects(machine, ref counterSets); if (res != 0) { @@ -330,7 +329,7 @@ private void ProcessListSetPerMachine(string machine) CultureInfo culture = GetCurrentCulture(); List> characterReplacementList = null; - StringCollection validPaths = new StringCollection(); + List validPaths = new List(); _cultureAndSpecialCharacterMap.TryGetValue(culture.Name, out characterReplacementList); @@ -356,8 +355,8 @@ private void ProcessListSetPerMachine(string machine) continue; } - StringCollection counterSetCounters = new StringCollection(); - StringCollection counterSetInstances = new StringCollection(); + List counterSetCounters = new List(); + List counterSetInstances = new List(); res = _pdhHelper.EnumObjectItems(machine, counterSet, ref counterSetCounters, ref counterSetInstances); if (res == PdhResults.PDH_ACCESS_DENIED) @@ -444,7 +443,7 @@ private void ProcessGetCounter() _cultureAndSpecialCharacterMap.TryGetValue(culture.Name, out characterReplacementList); } - StringCollection allExpandedPaths = new StringCollection(); + List allExpandedPaths = new List(); foreach (string path in paths) { string localizedPath = path; @@ -468,7 +467,7 @@ private void ProcessGetCounter() } } - StringCollection expandedPaths; + List expandedPaths; res = _pdhHelper.ExpandWildCardPath(localizedPath, out expandedPaths); if (res != 0) { diff --git a/src/Microsoft.PowerShell.Commands.Diagnostics/GetEventCommand.cs b/src/Microsoft.PowerShell.Commands.Diagnostics/GetEventCommand.cs index 33e127565e6..b6f6561d0d0 100644 --- a/src/Microsoft.PowerShell.Commands.Diagnostics/GetEventCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Diagnostics/GetEventCommand.cs @@ -5,7 +5,6 @@ using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Collections.Specialized; using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Eventing.Reader; using System.Globalization; @@ -396,10 +395,10 @@ public SwitchParameter Oldest // Other private members and constants // private ResourceManager _resourceMgr = null; - private Dictionary _providersByLogMap = new Dictionary(); + private Dictionary> _providersByLogMap = new Dictionary>(); - private StringCollection _logNamesMatchingWildcard = null; - private StringCollection _resolvedPaths = new StringCollection(); + private List _logNamesMatchingWildcard = null; + private List _resolvedPaths = new List(); private List _accumulatedLogNames = new List(); private List _accumulatedProviderNames = new List(); @@ -771,7 +770,7 @@ private void ProcessFile() // for (int i = 0; i < _path.Length; i++) { - StringCollection resolvedPaths = ValidateAndResolveFilePath(_path[i]); + List resolvedPaths = ValidateAndResolveFilePath(_path[i]); foreach (string resolvedPath in resolvedPaths) { _resolvedPaths.Add(resolvedPath); @@ -1169,7 +1168,7 @@ private string BuildStructuredQueryFromHashTable(EventLogSession eventLogSession { foreach (object elt in (Array)hash[hashkey_path_lc]) { - StringCollection resolvedPaths = ValidateAndResolveFilePath(elt.ToString()); + List resolvedPaths = ValidateAndResolveFilePath(elt.ToString()); foreach (string resolvedPath in resolvedPaths) { queriedLogsQueryMap.Add(filePrefix + resolvedPath.ToLowerInvariant(), @@ -1181,7 +1180,7 @@ private string BuildStructuredQueryFromHashTable(EventLogSession eventLogSession } else { - StringCollection resolvedPaths = ValidateAndResolveFilePath(hash[hashkey_path_lc].ToString()); + List resolvedPaths = ValidateAndResolveFilePath(hash[hashkey_path_lc].ToString()); foreach (string resolvedPath in resolvedPaths) { queriedLogsQueryMap.Add(filePrefix + resolvedPath.ToLowerInvariant(), @@ -1752,9 +1751,9 @@ private bool StringToDateTime(string dtString, ref DateTime dt) // Writes non-terminating errors for invalid paths // and returns an empty collection. // - private StringCollection ValidateAndResolveFilePath(string path) + private List ValidateAndResolveFilePath(string path) { - StringCollection retColl = new StringCollection(); + List retColl = new List(); Collection resolvedPathSubset = null; try @@ -1872,7 +1871,7 @@ private void CheckHashTablesForNullValues() // and will may produce garbage if the _filterXPath expression provided by the user is invalid. // However, we are relying on the EventLog XPath parser to reject the garbage later on. // - private string AddProviderPredicatesToFilter(StringCollection providers) + private string AddProviderPredicatesToFilter(List providers) { if (providers.Count == 0) { @@ -1910,7 +1909,7 @@ private string AddProviderPredicatesToFilter(StringCollection providers) // "System/Provider[@Name='a' or @Name='b']" // for all provider names specified in the "providers" argument. // - private string BuildProvidersPredicate(StringCollection providers) + private string BuildProvidersPredicate(List providers) { if (providers.Count == 0) { @@ -2012,7 +2011,7 @@ private void AddLogsForProviderToInternalMap(EventLogSession eventLogSession, st WriteVerbose(string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("ProviderLogLink"), providerName, logLink.LogName)); - StringCollection provColl = new StringCollection(); + List provColl = new List(); provColl.Add(providerName.ToLowerInvariant()); _providersByLogMap.Add(logLink.LogName.ToLowerInvariant(), provColl); @@ -2022,7 +2021,7 @@ private void AddLogsForProviderToInternalMap(EventLogSession eventLogSession, st // // Log is there: add provider, if needed // - StringCollection coll = _providersByLogMap[logLink.LogName.ToLowerInvariant()]; + List coll = _providersByLogMap[logLink.LogName.ToLowerInvariant()]; if (!coll.Contains(providerName.ToLowerInvariant())) { @@ -2054,7 +2053,7 @@ private void FindLogNamesMatchingWildcards(EventLogSession eventLogSession, IEnu { if (_logNamesMatchingWildcard == null) { - _logNamesMatchingWildcard = new StringCollection(); + _logNamesMatchingWildcard = new List(); } else { diff --git a/src/Microsoft.PowerShell.Commands.Diagnostics/PdhHelper.cs b/src/Microsoft.PowerShell.Commands.Diagnostics/PdhHelper.cs index 1e703d66219..3f0b82b42b8 100644 --- a/src/Microsoft.PowerShell.Commands.Diagnostics/PdhHelper.cs +++ b/src/Microsoft.PowerShell.Commands.Diagnostics/PdhHelper.cs @@ -4,7 +4,6 @@ using System; using System.Collections; using System.Collections.Generic; -using System.Collections.Specialized; using System.Diagnostics; using System.Globalization; using System.Runtime.InteropServices; @@ -426,12 +425,12 @@ public void Dispose() private Dictionary _consumerPathToHandleAndInstanceMap = new Dictionary(); /// - /// A helper reading in a Unicode string with embedded NULLs and splitting it into a StringCollection. + /// A helper reading in a Unicode string with embedded NULLs and splitting it into a List. /// /// /// /// - private void ReadPdhMultiString(ref IntPtr strNative, Int32 strSize, ref StringCollection strColl) + private void ReadPdhMultiString(ref IntPtr strNative, Int32 strSize, ref List strColl) { Debug.Assert(strSize >= 2); int offset = 0; @@ -534,7 +533,7 @@ public uint ConnectToDataSource(string dataSourceName) return res; } - public uint ConnectToDataSource(StringCollection blgFileNames) + public uint ConnectToDataSource(List blgFileNames) { if (blgFileNames.Count == 1) { @@ -609,7 +608,7 @@ public uint SetQueryTimeRange(DateTime startTime, DateTime endTime) return PdhSetQueryTimeRange(_hQuery, ref pTimeInfo); } - public uint EnumBlgFilesMachines(ref StringCollection machineNames) + public uint EnumBlgFilesMachines(ref List machineNames) { IntPtr MachineListTcharSizePtr = new IntPtr(0); uint res = PdhHelper.PdhEnumMachinesH(_hDataSource, IntPtr.Zero, ref MachineListTcharSizePtr); @@ -637,7 +636,7 @@ public uint EnumBlgFilesMachines(ref StringCollection machineNames) return res; } - public uint EnumObjects(string machineName, ref StringCollection objectNames) + public uint EnumObjects(string machineName, ref List objectNames) { IntPtr pBufferSize = new IntPtr(0); uint res = PdhEnumObjectsH(_hDataSource, machineName, IntPtr.Zero, ref pBufferSize, PerfDetail.PERF_DETAIL_WIZARD, false); @@ -665,7 +664,7 @@ public uint EnumObjects(string machineName, ref StringCollection objectNames) return res; } - public uint EnumObjectItems(string machineName, string objectName, ref StringCollection counterNames, ref StringCollection instanceNames) + public uint EnumObjectItems(string machineName, string objectName, ref List counterNames, ref List instanceNames) { IntPtr pCounterBufferSize = new IntPtr(0); IntPtr pInstanceBufferSize = new IntPtr(0); @@ -745,11 +744,11 @@ public uint EnumObjectItems(string machineName, string objectName, ref StringCol return res; } - public uint GetValidPathsFromFiles(ref StringCollection validPaths) + public uint GetValidPathsFromFiles(ref List validPaths) { Debug.Assert(_hDataSource != null && !_hDataSource.IsInvalid, "Call ConnectToDataSource before GetValidPathsFromFiles"); - StringCollection machineNames = new StringCollection(); + List machineNames = new List(); uint res = this.EnumBlgFilesMachines(ref machineNames); if (res != 0) { @@ -758,7 +757,7 @@ public uint GetValidPathsFromFiles(ref StringCollection validPaths) foreach (string machine in machineNames) { - StringCollection counterSets = new StringCollection(); + List counterSets = new List(); res = this.EnumObjects(machine, ref counterSets); if (res != 0) { @@ -769,8 +768,8 @@ public uint GetValidPathsFromFiles(ref StringCollection validPaths) { // Console.WriteLine("Counter set " + counterSet); - StringCollection counterSetCounters = new StringCollection(); - StringCollection counterSetInstances = new StringCollection(); + List counterSetCounters = new List(); + List counterSetInstances = new List(); res = this.EnumObjectItems(machine, counterSet, ref counterSetCounters, ref counterSetInstances); if (res != 0) @@ -1056,9 +1055,9 @@ public uint LookupPerfNameByIndex(string machineName, uint index, out string loc public uint GetValidPaths(string machineName, string objectName, - ref StringCollection counters, - ref StringCollection instances, - ref StringCollection validPaths) + ref List counters, + ref List instances, + ref List validPaths) { uint res = 0; @@ -1097,7 +1096,7 @@ public uint GetValidPaths(string machineName, return res; } - public uint AddCounters(ref StringCollection validPaths, bool bFlushOldCounters) + public uint AddCounters(ref List validPaths, bool bFlushOldCounters) { Debug.Assert(_hQuery != null && !_hQuery.IsInvalid); @@ -1281,9 +1280,9 @@ public uint ReadNextSet(out PerformanceCounterSampleSet nextSet, bool bSkipReadi return res; } - public uint ExpandWildCardPath(string path, out StringCollection expandedPaths) + public uint ExpandWildCardPath(string path, out List expandedPaths) { - expandedPaths = new StringCollection(); + expandedPaths = new List(); IntPtr pcchPathListLength = new IntPtr(0); uint res = PdhExpandWildCardPathH(_hDataSource, diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/ParsePathCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/ParsePathCommand.cs index a1dd7895fc1..000a3f7ebca 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/ParsePathCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/ParsePathCommand.cs @@ -2,8 +2,8 @@ // Licensed under the MIT License. using System; +using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Collections.Specialized; using System.Management.Automation; using System.Management.Automation.Internal; @@ -184,7 +184,7 @@ public string[] LiteralPath /// protected override void ProcessRecord() { - StringCollection pathsToParse = new StringCollection(); + List pathsToParse = new List(); if (Resolve) { diff --git a/src/System.Management.Automation/FormatAndOutput/common/BaseOutputtingCommand.cs b/src/System.Management.Automation/FormatAndOutput/common/BaseOutputtingCommand.cs index bb8305b2fdc..635fd3ed400 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/BaseOutputtingCommand.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/BaseOutputtingCommand.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Collections.Specialized; using System.Management.Automation; using System.Management.Automation.Internal; @@ -1117,33 +1116,42 @@ private void InternalInitialize(ListViewEntry lve) internal static string[] GetProperties(ListViewEntry lve) { - StringCollection props = new StringCollection(); - foreach (ListViewField lvf in lve.listViewFieldList) + int count = lve.listViewFieldList.Count; + + if (count == 0) { - props.Add(lvf.label ?? lvf.propertyName); + return null; } - if (props.Count == 0) - return null; - string[] retVal = new string[props.Count]; - props.CopyTo(retVal, 0); - return retVal; + string[] props = new string[count]; + + for (int i = 0; i < count; ++i) + { + ListViewField lvf = lve.listViewFieldList[i]; + props[i] = lvf.label ?? lvf.propertyName; + } + + return props; } internal static string[] GetValues(ListViewEntry lve) { - StringCollection vals = new StringCollection(); + int count = lve.listViewFieldList.Count; - foreach (ListViewField lvf in lve.listViewFieldList) + if (count == 0) { - vals.Add(lvf.formatPropertyField.propertyValue); + return null; } - if (vals.Count == 0) - return null; - string[] retVal = new string[vals.Count]; - vals.CopyTo(retVal, 0); - return retVal; + string[] vals = new string[count]; + + for (int i = 0; i < count; ++i) + { + ListViewField lvf = lve.listViewFieldList[i]; + vals[i] = lvf.formatPropertyField.propertyValue; + } + + return vals; } /// diff --git a/src/System.Management.Automation/FormatAndOutput/common/ComplexWriter.cs b/src/System.Management.Automation/FormatAndOutput/common/ComplexWriter.cs index 74031dc515c..bdebdb45019 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/ComplexWriter.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/ComplexWriter.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Collections.Specialized; using System.Globalization; using System.Management.Automation.Internal; using System.Text; @@ -168,7 +167,7 @@ private void WriteToScreen() // error checking on invalid values // generate the lines using the computed widths - StringCollection sc = StringManipulationHelper.GenerateLines(_lo.DisplayCells, _stringBuffer.ToString(), + List lines = StringManipulationHelper.GenerateLines(_lo.DisplayCells, _stringBuffer.ToString(), firstLineWidth, followingLinesWidth); // compute padding @@ -187,7 +186,7 @@ private void WriteToScreen() // now write the lines on the screen bool firstLine = true; - foreach (string s in sc) + foreach (string s in lines) { if (firstLine) { @@ -388,7 +387,7 @@ private static IEnumerable GetWords(string s) yield return result; } - internal static StringCollection GenerateLines(DisplayCells displayCells, string val, int firstLineLen, int followingLinesLen) + internal static List GenerateLines(DisplayCells displayCells, string val, int firstLineLen, int followingLinesLen) { if (s_cultureCollection.Contains(CultureInfo.CurrentCulture.TwoLetterISOLanguageName)) { @@ -400,9 +399,9 @@ internal static StringCollection GenerateLines(DisplayCells displayCells, string } } - private static StringCollection GenerateLinesWithoutWordWrap(DisplayCells displayCells, string val, int firstLineLen, int followingLinesLen) + private static List GenerateLinesWithoutWordWrap(DisplayCells displayCells, string val, int firstLineLen, int followingLinesLen) { - StringCollection retVal = new StringCollection(); + List retVal = new List(); if (string.IsNullOrEmpty(val)) { @@ -483,7 +482,7 @@ private static StringCollection GenerateLinesWithoutWordWrap(DisplayCells displa private sealed class SplitLinesAccumulator { - internal SplitLinesAccumulator(StringCollection retVal, int firstLineLen, int followingLinesLen) + internal SplitLinesAccumulator(List retVal, int firstLineLen, int followingLinesLen) { _retVal = retVal; _firstLineLen = firstLineLen; @@ -510,15 +509,15 @@ internal int ActiveLen } } - private StringCollection _retVal; + private List _retVal; private bool _addedFirstLine; private int _firstLineLen; private int _followingLinesLen; } - private static StringCollection GenerateLinesWithWordWrap(DisplayCells displayCells, string val, int firstLineLen, int followingLinesLen) + private static List GenerateLinesWithWordWrap(DisplayCells displayCells, string val, int firstLineLen, int followingLinesLen) { - StringCollection retVal = new StringCollection(); + List retVal = new List(); if (string.IsNullOrEmpty(val)) { diff --git a/src/System.Management.Automation/FormatAndOutput/common/FormattingObjectsDeserializer.cs b/src/System.Management.Automation/FormatAndOutput/common/FormattingObjectsDeserializer.cs index 8609d35c9a9..a4dd4c545d2 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/FormattingObjectsDeserializer.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/FormattingObjectsDeserializer.cs @@ -176,7 +176,7 @@ private static string[] ReadStringArrayHelper (object rawObject, string property return null; // copy to string collection, since, a priori, we do not know the length - StringCollection temp = new StringCollection (); + List temp = new List(); foreach (string s in e) temp.Add (s); diff --git a/src/System.Management.Automation/FormatAndOutput/common/ListWriter.cs b/src/System.Management.Automation/FormatAndOutput/common/ListWriter.cs index 91a7b8698a6..b70e9d114ee 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/ListWriter.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/ListWriter.cs @@ -2,7 +2,7 @@ // Licensed under the MIT License. using System; -using System.Collections.Specialized; +using System.Collections.Generic; using System.Diagnostics; using System.Management.Automation.Internal; @@ -207,21 +207,21 @@ private void WriteSingleLineHelper(string prependString, string line, LineOutput int fieldCellCount = _columnWidth - _propertyLabelsDisplayLength; // split the lines - StringCollection sc = StringManipulationHelper.GenerateLines(lo.DisplayCells, line, fieldCellCount, fieldCellCount); + List lines = StringManipulationHelper.GenerateLines(lo.DisplayCells, line, fieldCellCount, fieldCellCount); // padding to use in the lines after the first string padding = StringUtil.Padding(_propertyLabelsDisplayLength); // display the string collection - for (int k = 0; k < sc.Count; k++) + for (int k = 0; k < lines.Count; k++) { if (k == 0) { - lo.WriteLine(prependString + sc[k]); + lo.WriteLine(prependString + lines[k]); } else { - lo.WriteLine(padding + sc[k]); + lo.WriteLine(padding + lines[k]); } } } diff --git a/src/System.Management.Automation/FormatAndOutput/common/OutputManager.cs b/src/System.Management.Automation/FormatAndOutput/common/OutputManager.cs index b07731c3e04..5ae20793ba7 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/OutputManager.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/OutputManager.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Collections.Specialized; using System.Management.Automation; using System.Management.Automation.Internal; @@ -185,7 +184,7 @@ public void Dispose() /// /// Ordered list of ETS type names this object is handling. /// - private StringCollection _applicableTypes = new StringCollection(); + private List _applicableTypes = new List(); } /// diff --git a/src/System.Management.Automation/FormatAndOutput/common/TableWriter.cs b/src/System.Management.Automation/FormatAndOutput/common/TableWriter.cs index 54aaa9438c5..77f3252c825 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/TableWriter.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/TableWriter.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Collections.Specialized; using System.Management.Automation.Internal; using System.Text; @@ -256,28 +255,32 @@ private string[] GenerateTableRow(string[] values, ReadOnlySpan alignment, return null; } - StringCollection[] scArray = new StringCollection[validColumnCount]; + List[] stringListArray = new List[validColumnCount]; + int length = stringListArray.Length; bool addPadding = true; - for (int k = 0; k < scArray.Length; k++) + for (int k = 0; k < length; k++) { // for the last column, don't pad it with trailing spaces - if (k == scArray.Length - 1) + if (k == length - 1) { addPadding = false; } // obtain a set of tokens for each field - scArray[k] = GenerateMultiLineRowField(values[validColumnArray[k]], validColumnArray[k], - alignment[validColumnArray[k]], ds, addPadding); + int pos = validColumnArray[k]; + List stringList = GenerateMultiLineRowField( + values[pos], _si.columnInfo[pos].width, alignment[pos], ds, addPadding); + + stringListArray[k] = stringList; // NOTE: the following padding operations assume that we // pad with a blank (or any character that ALWAYS maps to a single screen cell if (k > 0) { // skipping the first ones, add a separator for concatenation - for (int j = 0; j < scArray[k].Count; j++) + for (int j = 0; j < stringList.Count; j++) { - scArray[k][j] = StringUtil.Padding(ScreenInfo.separatorCharacterCount) + scArray[k][j]; + stringList[j] = StringUtil.Padding(ScreenInfo.separatorCharacterCount) + stringList[j]; } } else @@ -285,9 +288,9 @@ private string[] GenerateTableRow(string[] values, ReadOnlySpan alignment, // add indentation padding if needed if (_startColumn > 0) { - for (int j = 0; j < scArray[k].Count; j++) + for (int j = 0; j < stringList.Count; j++) { - scArray[k][j] = StringUtil.Padding(_startColumn) + scArray[k][j]; + stringList[j] = StringUtil.Padding(_startColumn) + stringList[j]; } } } @@ -296,10 +299,10 @@ private string[] GenerateTableRow(string[] values, ReadOnlySpan alignment, // now we processed all the rows columns and we need to find the cell that occupies the most // rows int screenRows = 0; - for (int k = 0; k < scArray.Length; k++) + for (int k = 0; k < length; k++) { - if (scArray[k].Count > screenRows) - screenRows = scArray[k].Count; + if (stringListArray[k].Count > screenRows) + screenRows = stringListArray[k].Count; } // column headers can span multiple rows if the width of the column is shorter than the header text like: @@ -315,9 +318,9 @@ private string[] GenerateTableRow(string[] values, ReadOnlySpan alignment, System.Span lastColWithContent = screenRows <= OutCommandInner.StackAllocThreshold ? stackalloc int[screenRows] : new int[screenRows]; for (int row = 0; row < screenRows; row++) { - for (int col = 0; col < scArray.Length; col++) + for (int col = 0; col < length; col++) { - if (scArray[col].Count > row) + if (stringListArray[col].Count > row) { lastColWithContent[row] = col; } @@ -325,12 +328,12 @@ private string[] GenerateTableRow(string[] values, ReadOnlySpan alignment, } // add padding for the columns that are shorter - for (int col = 0; col < scArray.Length; col++) + for (int col = 0; col < length; col++) { int paddingBlanks = 0; // don't pad if last column - if (col < scArray.Length - 1) + if (col < length - 1) { paddingBlanks = _si.columnInfo[validColumnArray[col]].width; if (col > 0) @@ -343,7 +346,7 @@ private string[] GenerateTableRow(string[] values, ReadOnlySpan alignment, } } - int paddingEntries = screenRows - scArray[col].Count; + int paddingEntries = screenRows - stringListArray[col].Count; if (paddingEntries > 0) { for (int row = screenRows - paddingEntries; row < screenRows; row++) @@ -351,11 +354,11 @@ private string[] GenerateTableRow(string[] values, ReadOnlySpan alignment, // if the column is beyond the last column with content, just use empty string if (col > lastColWithContent[row]) { - scArray[col].Add(string.Empty); + stringListArray[col].Add(string.Empty); } else { - scArray[col].Add(StringUtil.Padding(paddingBlanks)); + stringListArray[col].Add(StringUtil.Padding(paddingBlanks)); } } } @@ -367,16 +370,16 @@ private string[] GenerateTableRow(string[] values, ReadOnlySpan alignment, { StringBuilder sb = new StringBuilder(); // for a given row, walk the columns - for (int col = 0; col < scArray.Length; col++) + for (int col = 0; col < length; col++) { // if the column is the last column with content, we need to trim trailing whitespace, unless there is only one row if (col == lastColWithContent[row] && screenRows > 1) { - sb.Append(scArray[col][row].TrimEnd()); + sb.Append(stringListArray[col][row].TrimEnd()); } else { - sb.Append(scArray[col][row]); + sb.Append(stringListArray[col][row]); } } @@ -386,21 +389,20 @@ private string[] GenerateTableRow(string[] values, ReadOnlySpan alignment, return rows; } - private StringCollection GenerateMultiLineRowField(string val, int k, int alignment, DisplayCells dc, bool addPadding) + private static List GenerateMultiLineRowField(string val, int width, int alignment, DisplayCells dc, bool addPadding) { - StringCollection sc = StringManipulationHelper.GenerateLines(dc, val, - _si.columnInfo[k].width, _si.columnInfo[k].width); + List lines = StringManipulationHelper.GenerateLines(dc, val, width, width); if (addPadding || alignment == TextAlignment.Right || alignment == TextAlignment.Center) { // if length is shorter, do some padding - for (int col = 0; col < sc.Count; col++) + for (int col = 0; col < lines.Count; col++) { - if (dc.Length(sc[col]) < _si.columnInfo[k].width) - sc[col] = GenerateRowField(sc[col], _si.columnInfo[k].width, alignment, dc, addPadding); + if (dc.Length(lines[col]) < width) + lines[col] = GenerateRowField(lines[col], width, alignment, dc, addPadding); } } - return sc; + return lines; } private string GenerateRow(string[] values, ReadOnlySpan alignment, DisplayCells dc) diff --git a/src/System.Management.Automation/FormatAndOutput/out-console/ConsoleLineOutput.cs b/src/System.Management.Automation/FormatAndOutput/out-console/ConsoleLineOutput.cs index b6cde18fb65..0d3c2fb8c35 100644 --- a/src/System.Management.Automation/FormatAndOutput/out-console/ConsoleLineOutput.cs +++ b/src/System.Management.Automation/FormatAndOutput/out-console/ConsoleLineOutput.cs @@ -6,12 +6,12 @@ //#define TEST_MULTICELL_ON_SINGLE_CELL_LOCALE using System; -using System.Collections.Specialized; using System.Management.Automation; using System.Management.Automation.Internal; using System.Management.Automation.Host; using Dbg = System.Management.Automation.Diagnostics; +using System.Collections.Generic; // interfaces for host interaction @@ -550,7 +550,7 @@ internal PromptResponse PromptUser(PSHostUserInterface console) /// /// Cached string(s) valid during a sequence of ComputePromptLines()/PromptUser() /// - private StringCollection _actualPrompt; + private List _actualPrompt; /// /// Prompt string as passed at initialization.