[API Proposal]: Allow ControlCollection.AddRange to use params keyword.
See original GitHub issueBackground and motivation
Currently Control.ControlCollection.AddRange method is accepting an array of Control
, this means each time that we want to add multiple controls at once, we have to make a new array. By using params
keyword using this method will become easier.
API Proposal
- Add
params
keyword to all collectionAddRange
methods that don’t already have it.
namespace System.Windows.Forms;
public class Control
{
public class ControlCollection
{
public virtual void AddRange(params Control[] controls);
}
}
Likewise we want to update our other collections that have an AddRange
:
// Note that parameter names are left as they currently are.
System.ComponentModel.Design.DesignerActionListCollection.AddRange(params DesignerActionList[] value)
System.Windows.Forms.AutoCompleteStringCollection.AddRange(params string[] value)
System.Windows.Forms.ComboBox.ObjectCollection.AddRange(params object[] items)
System.Windows.Forms.Design.Behavior.BehaviorServiceAdornerCollection.AddRange(params Adorner[] value)
System.Windows.Forms.Design.Behavior.GlyphCollection.AddRange(params Glyph[] value)
System.Windows.Forms.ImageList.ImageCollection.AddRange(params Image[] images)
System.Windows.Forms.ListBox.IntegerCollection.AddRange(params int[] items)
System.Windows.Forms.ListBox.ObjectCollection.AddRange(params object[] items)
System.Windows.Forms.ListView.ListViewItemCollection.AddRange(params ListViewItem[] items)
System.Windows.Forms.ListView.ColumnHeaderCollection.AddRange(params ColumnHeader[] values)
System.Windows.Forms.ListViewGroupCollection.AddRange(params ListViewGroup[] groups)
System.Windows.Forms.ListViewItem.ListViewSubItemCollection.AddRange(params ListViewSubItem[] items)
System.Windows.Forms.ListViewItem.ListViewSubItemCollection.AddRange(params string[] items)
System.Windows.Forms.TabControl.TabPageCollection.AddRange(params TabPage[] pages)
System.Windows.Forms.ToolStripItemCollection.AddRange(params ToolStripItem[] toolStripItems)
System.Windows.Forms.ToolStripPanel.ToolStripPanelRowCollection.AddRange(params ToolStripPanelRow[] value)
System.Windows.Forms.TreeNodeCollection.AddRange(params TreeNode[] nodes)
API Usage
this.Controls.AddRange(this.BtnControl1, this.BtnControl2);
Risks
No known risks.
Will this feature affect UI controls?
- No, VS Designer doesn’t need to support this feature.
- The impact will be easier use of this method by users.
- No, this feature doesn’t need to be localized.
Issue Analytics
- State:
- Created 6 months ago
- Reactions:3
- Comments:12 (9 by maintainers)
Top Results From Across the Web
Refactor `ControlCollection.AddRange` to use params ...
Proposed changes Add params keyword to arguments of ControlCollection.AddRange method. Regression? No Risk None Microsoft Reviewers: Open in CodeFlow.
Read more >[API Proposal]: Allow ControlCollection.AddRange to use ...
Windows Forms is a .NET UI framework for building Windows desktop applications. - [API Proposal]: Allow ControlCollection.AddRange to use params keyword.
Read more >Form.ControlCollection.Add(Control) Method
You can use this method to add controls to the form. If you want to add a group of already created controls to...
Read more >params keyword for parameter arrays - C# reference
In this article ... By using the params keyword, you can specify a method parameter that takes a variable number of arguments. The...
Read more >C# 10 in a Nutshell
C# also allows parts of your code to be dynamically typed via the dynamic keyword. However, C# remains a predominantly.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@elachlan
Yes.
@JeremyKuhne can I commit the changes to my current PR? Or I have to revert the last commit from it first?
Video