question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Convert `ArrayList` usage to `List<T>` where possible

See original GitHub issue

Is your feature request related to a problem? Please describe

Winforms uses Arraylist extensively.

Describe the solution you’d like and alternatives you’ve considered

Convert Arraylist usage to List<T> to reduce boxing and improve memory utilization.

Will this feature affect UI controls?

N/A

Related: #2644

Remaining occurrences in System.Windows.Forms.Design

File Line Count
src\System\ComponentModel\Design\ExceptionCollection.cs 33
src\System\Windows\Forms\Design\ToolStripItemDataObject.cs 34
src\System\Windows\Forms\Design\ControlDesigner.DesignerControlCollectionCodeDomSerializer.cs 38
src\System\Windows\Forms\Design\UpDownBaseDesigner.cs 63
src\System\Windows\Forms\Design\DesignBindingValueUIHandler.cs 66
src\System\Windows\Forms\Design\ImageListImageEditor.cs 108
src\System\Windows\Forms\Design\ImageCollectionEditor.cs 113
src\System\Windows\Forms\Design\GroupBoxDesigner.cs 124
src\System\Windows\Forms\Design\ComboBoxDesigner.cs 128
src\System\Windows\Forms\Design\LabelDesigner.cs 146
src\System\Windows\Forms\Design\TextBoxBaseDesigner.cs 148
src\System\Windows\Forms\Design\OleDragDropHandler.CfCodeToolboxItem.cs 162
src\System\Windows\Forms\Design\ButtonBaseDesigner.cs 218
src\System\Windows\Forms\Design\Behavior\ContainerSelectorBehavior.cs 230
src\System\Windows\Forms\Design\ToolStripAdornerWindowService.cs 256
src\System\Windows\Forms\Design\BaseContextMenuStrip.cs 290
src\System\Windows\Forms\Design\OleDragDropHandler.ComponentDataObject.cs 302
src\System\ComponentModel\Design\InheritedPropertyDescriptor.cs 308
src\System\Windows\Forms\Design\Behavior\ToolboxItemSnapLineBehavior.cs 338
src\System\ComponentModel\Design\CollectionEditor.cs 347
src\System\Windows\Forms\Design\FormDocumentDesigner.cs 432
src\System\ComponentModel\Design\SelectionService.cs 446
src\System\Windows\Forms\Design\Behavior\SelectionManager.cs 458
src\System\ComponentModel\Design\DesignSurface.cs 491
src\System\Windows\Forms\Design\DesignerFrame.cs 576
src\System\Windows\Forms\Design\ToolStripDesignerUtils.cs 584
src\System\ComponentModel\Design\Serialization\CollectionCodeDomSerializer.cs 648
src\System\Windows\Forms\Design\DesignerUtils.cs 816
src\System\Windows\Forms\Design\Behavior\ResizeBehavior.cs 819
src\System\ComponentModel\Design\Serialization\BasicDesignerLoader.cs 857
src\System\ComponentModel\Design\Serialization\DesignerSerializationManager.cs 896
src\System\Windows\Forms\Design\ToolStripItemBehavior.cs 905
src\System\Windows\Forms\Design\Behavior\DropSourceBehavior.cs 1029
src\System\Windows\Forms\Design\OleDragDropHandler.cs 1045
src\System\Windows\Forms\Design\ToolStripItemDesigner.cs 1177
src\System\ComponentModel\Design\CollectionEditor.CollectionEditorCollectionForm.cs 1223
src\System\ComponentModel\Design\Serialization\CodeDomComponentSerializationService.cs 1471
src\System\ComponentModel\Design\DesignerHost.cs 1615
src\System\Windows\Forms\Design\ToolStripKeyboardHandlingService.cs 1891
src\System\Windows\Forms\Design\ControlDesigner.cs 2205
src\System\Windows\Forms\Design\ToolStripDesigner.cs 2260
src\System\Windows\Forms\Design\ParentControlDesigner.cs 2378
src\System\Windows\Forms\Design\ToolStripMenuItemDesigner.cs 2527
src\System\ComponentModel\Design\Serialization\CodeDomSerializerBase.cs 3020

Issue Analytics

  • State:open
  • Created 10 months ago
  • Reactions:4
  • Comments:17 (17 by maintainers)

github_iconTop GitHub Comments

2reactions
Jerichocommented, Dec 11, 2022

Here’s the list of classes that will benefit from replacing ArrayList with List<T> (I’ll continuously maintain this list as I discover more classes):

  • WeakRefCollection: use List<WeakRefObject?> instead of ArrayList
  • AutoCompleteStringCollection:
  • ArrangedElementCollection: use List<IArrangedElement> instead of ArrayList
  • TableLayoutStyleCollection: use List<TableLayoutStyle> instead of ArrayList
  • DesignerEventService: use List<IDesignerHost> instead of ArrayList
  • ExtenderProviderService: use List<IExtenderProvider> instead of ArrayList
  • MenuCommandService: use List<DesignerVerb> instead of ArrayList
  • ReferenceService: there are three ArrayList. Two of them can be replaced with List<IComponent> and the other one can be replaced with List<ReferenceHolder>
  • CodeDomComponentSerializationService: there are two ArrayList. One can be replaced with List<string> and the other one can be replaced with List<CodeExpression>
  • UndoEngine: there are five array lists in the class. Two of them can be replaced with List<IComponent>, and the remaining three can be replaced with List<UndoEvent>, List<ChangeUndoEvent> and List<AddRemoveUndoEvent> respectively.
  • BehaviorService: replace ArrayList with List<Behavior>
  • DragAssistanceManager: there are seven ArrayList in this class. Four of them can be replaced with List<SnapLine>, one can be replaced with List<SnapLineType> and two can be replaced with List<Line>
  • DocumentDesigner: replace ArrayList with List<IComponent>
  • PbrsForward: replace ArrayList with List<BufferedKey>
  • ToolStripKeyboardHandlingService: there are two ArrayList that can be replaced with List<MenuCommand>
  • DataGridView: replace ArrayList with List<DataGridViewRow>
  • DataGridViewCellCollection: replace ArrayList with List<DataGridViewCell>
  • DataGridViewColumnCollection: replace ArrayList with List<DataGridViewColumn>
  • DataGridViewSelectedCellCollection: replace ArrayList with List<DataGridViewCell>
  • DataGridViewSelectedColumnCollection: replace ArrayList with List<DataGridViewColumn>
  • DataGridViewSelectedRowCollection: replace ArrayList with List<DataGridViewRow>
  • PropertyGridView: replace ArrayList with List<GridEntryCollection>
  • BindingCollection: replace ArrayList with List<Binding>
  • Com2IManagedPerPropertyBrowsingHandler: replace ArrayList with List<Attribute>

Here are classes that use an ArrayList and the type of the elements is object. Is it worth it to convert to List<object>?

  • DataGridViewComboBoxCell
  • SelectionService: Currently the ArrayList contains objects but I suspect the intent is to keep a reference of visual components rather than objects. Therefore, I think List<IComponent> would be more appropriate
1reaction
Jerichocommented, Nov 9, 2022

I would be happy to contribute. I will start with combing through the code base to identify the various classes that would be affected.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Convert ArrayList<String> to java.util.List [closed]
An ArrayList<anything> is already a List<anything> , because ArrayList implements the List interface. No casting is necessary. Share.
Read more >
Java ArrayList Conversions To Other Collections
Answer: To convert an ArrayList to an Array in Java, one can use the toArray ( ) method from ArrayList API that converts...
Read more >
Converting Between an Array and a List in Java
In this quick tutorial, we're going to learn how to convert between an Array and a List using core Java libraries, Guava and...
Read more >
How do you turn an ArrayList into a Set in Java
An ArrayList can be converted to a set object using Set constructor. The resultant set will elliminate any duplicate entry present in the ......
Read more >
Java Program to Convert an Array into a List
Therefore the Array can be converted into the List with the help of the Collections.addAll() method. Algorithm: Get the Array to be converted....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found