diff --git a/src/System.Drawing.Common/src/System/Drawing/Printing/PrinterSettings.StringCollection.cs b/src/System.Drawing.Common/src/System/Drawing/Printing/PrinterSettings.StringCollection.cs index 15dc585aa9c..d063cdd2144 100644 --- a/src/System.Drawing.Common/src/System/Drawing/Printing/PrinterSettings.StringCollection.cs +++ b/src/System.Drawing.Common/src/System/Drawing/Printing/PrinterSettings.StringCollection.cs @@ -15,7 +15,7 @@ public class StringCollection : ICollection, IEnumerable /// /// Initializes a new instance of the class. /// - public StringCollection(string[] array) => _list = new(array); + public StringCollection(string[] array) => _list = [..array]; /// /// Gets a value indicating the number of strings. diff --git a/src/System.Private.Windows.Core/src/System/Collections/Generic/CollectionExtensions.cs b/src/System.Private.Windows.Core/src/System/Collections/Generic/CollectionExtensions.cs index 15dd20bbf5c..eb0852ff048 100644 --- a/src/System.Private.Windows.Core/src/System/Collections/Generic/CollectionExtensions.cs +++ b/src/System.Private.Windows.Core/src/System/Collections/Generic/CollectionExtensions.cs @@ -25,7 +25,7 @@ internal static List CreateTrimmedList(this IReadOnlyList readOnlyList, } // Fall back to just setting the count (by removing). - List list = new(readOnlyList); + List list = [..readOnlyList]; list.RemoveRange(count, list.Count - count); return list; } diff --git a/src/System.Private.Windows.GdiPlus/System/Drawing/IIcon.cs b/src/System.Private.Windows.GdiPlus/System/Drawing/IIcon.cs index 7b53bdaf0ef..5eed2338f87 100644 --- a/src/System.Private.Windows.GdiPlus/System/Drawing/IIcon.cs +++ b/src/System.Private.Windows.GdiPlus/System/Drawing/IIcon.cs @@ -5,5 +5,5 @@ namespace System.Drawing; internal interface IIcon : IHandle { - public Size Size { get; } + Size Size { get; } } diff --git a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/CollectionEditor.CollectionEditorCollectionForm.cs b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/CollectionEditor.CollectionEditorCollectionForm.cs index e5428772cc5..d30b80ffb1f 100644 --- a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/CollectionEditor.CollectionEditorCollectionForm.cs +++ b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/CollectionEditor.CollectionEditorCollectionForm.cs @@ -807,7 +807,7 @@ private void PerformRemove() { if (_listBox.SelectedItems.Count > 1) { - List toBeDeleted = _listBox.SelectedItems.Cast().ToList(); + List toBeDeleted = [.._listBox.SelectedItems.Cast()]; foreach (ListItem item in toBeDeleted) { RemoveInternal(item); diff --git a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/DesignerHost.cs b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/DesignerHost.cs index 0e5f01025de..1260870a2a2 100644 --- a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/DesignerHost.cs +++ b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/DesignerHost.cs @@ -1119,7 +1119,7 @@ void IDesignerLoaderHost.EndLoad(string? rootClassName, bool successful, ICollec _state[s_stateLoading] = true; Unload(); - List errorList = errorCollection is null ? [] : errorCollection.Cast().ToList(); + List errorList = errorCollection is null ? [] : [..errorCollection.Cast()]; errorList.Insert(0, ex); errorCollection = errorList; diff --git a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/Serialization/CodeDomComponentSerializationService.CodeDomSerializationStore.ComponentListCodeDomSerializer.cs b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/Serialization/CodeDomComponentSerializationService.CodeDomSerializationStore.ComponentListCodeDomSerializer.cs index 9eb2a6a7131..cb2e802899e 100644 --- a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/Serialization/CodeDomComponentSerializationService.CodeDomSerializationStore.ComponentListCodeDomSerializer.cs +++ b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/Serialization/CodeDomComponentSerializationService.CodeDomSerializationStore.ComponentListCodeDomSerializer.cs @@ -91,7 +91,7 @@ internal void Deserialize(IDesignerSerializationManager manager, Dictionary completeNames = new(objectNames); + HashSet completeNames = [..objectNames]; completeNames.UnionWith(_statementsTable.Keys); _objectState = new(objectState); diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/SelectionManager.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/SelectionManager.cs index 73648af22f8..23bbac7baf4 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/SelectionManager.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/SelectionManager.cs @@ -257,7 +257,7 @@ private void OnComponentAdded(object? source, ComponentEventArgs ce) /// private void OnBeginDrag(object? source, BehaviorDragDropEventArgs e) { - List dragComps = e.DragComponents.Cast().ToList(); + List dragComps = [..e.DragComponents.Cast()]; List glyphsToRemove = []; foreach (ControlBodyGlyph g in BodyGlyphAdorner.Glyphs) { @@ -412,7 +412,7 @@ private void OnSelectionChanged(object? sender, EventArgs? e) SelectionGlyphAdorner.Glyphs.Clear(); BodyGlyphAdorner.Glyphs.Clear(); - List selComps = _selectionService.GetSelectedComponents().Cast().ToList(); + List selComps = [.._selectionService.GetSelectedComponents().Cast()]; object? primarySelection = _selectionService.PrimarySelection; // add all control glyphs to all controls on rootComp diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/TableLayoutPanelBehavior.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/TableLayoutPanelBehavior.cs index eb6b29b06b8..a0514c3ac21 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/TableLayoutPanelBehavior.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/TableLayoutPanelBehavior.cs @@ -166,7 +166,7 @@ private void GetActiveStyleCollection(bool isColumn) { if ((_styles is null || isColumn != _currentColumnStyles) && _table is not null) { - _styles = ((TableLayoutStyleCollection)_changedProp.GetValue(_table)).Cast().ToList(); + _styles = [..((TableLayoutStyleCollection)_changedProp.GetValue(_table)).Cast()]; _currentColumnStyles = isColumn; } } diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/ToolStripPanelSelectionBehavior.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/ToolStripPanelSelectionBehavior.cs index e717ea8d0ea..1f5aa98e0e5 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/ToolStripPanelSelectionBehavior.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/ToolStripPanelSelectionBehavior.cs @@ -223,7 +223,7 @@ public override void OnDragDrop(Glyph? glyph, DragEventArgs e) if (e.Data is DropSourceBehavior.BehaviorDataObject data) { - components = new List(data.DragComponents); + components = [..data.DragComponents]; foreach (IComponent dragComponent in components) { diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/CommandSet.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/CommandSet.cs index d39ed9f7036..2b4645fd512 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/CommandSet.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/CommandSet.cs @@ -804,7 +804,7 @@ protected virtual void OnKeyMove(object? sender, EventArgs e) // Don't snap if we are moving a component in the ComponentTray if (invertSnap && useSnapLines && primaryControl is not null && comp.Site is not null) { - List selComps = SelectionService.GetSelectedComponents().Cast().ToList(); + List selComps = [..SelectionService.GetSelectedComponents().Cast()]; // create our snapline engine dragManager = new DragAssistanceManager(comp.Site, selComps); diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/FlowLayoutPanelDesigner .cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/FlowLayoutPanelDesigner .cs index 3db868f5c7c..0e92902a053 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/FlowLayoutPanelDesigner .cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/FlowLayoutPanelDesigner .cs @@ -757,7 +757,7 @@ protected override void OnDragEnter(DragEventArgs de) // Get the sorted drag controls. We use these for an internal drag. if (de.Data is DropSourceBehavior.BehaviorDataObject data) { - _dragControls = data.GetSortedDragControls(out int primaryIndex).OfType().ToList(); + _dragControls = [..data.GetSortedDragControls(out int primaryIndex).OfType()]; _primaryDragControl = _dragControls[primaryIndex]; } diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/OleDragDropHandler.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/OleDragDropHandler.cs index bcf00c49acb..8adc80b1c44 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/OleDragDropHandler.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/OleDragDropHandler.cs @@ -257,7 +257,7 @@ public IComponent[] CreateTool(ToolboxItem tool, Control? parent, int x, int y, { host?.Activate(); - List selectComps = new(comps); + List selectComps = [..comps]; for (int i = 0; i < comps.Length; i++) { diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/TableLayoutPanelDesigner.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/TableLayoutPanelDesigner.cs index 1ea69253c32..7f8d0da9405 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/TableLayoutPanelDesigner.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/TableLayoutPanelDesigner.cs @@ -952,7 +952,7 @@ private Control ExtractControlFromDragEvent(DragEventArgs de) { if (de.Data is DropSourceBehavior.BehaviorDataObject data) { - _dragComponents = new List(data.DragComponents); + _dragComponents = [..data.DragComponents]; return _dragComponents[0] as Control; } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ActiveX/AxHost.AxPropertyDescriptor.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ActiveX/AxHost.AxPropertyDescriptor.cs index 0d60dda12a2..d66e015cd5c 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/ActiveX/AxHost.AxPropertyDescriptor.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/ActiveX/AxHost.AxPropertyDescriptor.cs @@ -254,7 +254,7 @@ internal void UpdateAttributes() return; } - List attributes = new(AttributeArray!); + List attributes = [..AttributeArray!]; attributes.AddRange(_updateAttributes); AttributeArray = [.. attributes]; _updateAttributes.Clear(); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ComponentModel/COM2Interop/COM2PropertyDescriptor.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ComponentModel/COM2Interop/COM2PropertyDescriptor.cs index 33dd3d9e801..53a8148a3ca 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/ComponentModel/COM2Interop/COM2PropertyDescriptor.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/ComponentModel/COM2Interop/COM2PropertyDescriptor.cs @@ -238,7 +238,7 @@ public override AttributeCollection Attributes if (attributeList.Count > 0) { - newAttributes ??= new(AttributeArray); + newAttributes ??= [..AttributeArray]; // Push any new attributes into the base type. for (int i = 0; i < attributeList.Count; i++) diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ComponentModel/COM2Interop/ICom2ExtendedBrowsingHandler.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ComponentModel/COM2Interop/ICom2ExtendedBrowsingHandler.cs index 291b42c5d94..8fb6a7b67d7 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/ComponentModel/COM2Interop/ICom2ExtendedBrowsingHandler.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/ComponentModel/COM2Interop/ICom2ExtendedBrowsingHandler.cs @@ -21,11 +21,11 @@ internal unsafe interface ICom2ExtendedBrowsingHandler /// /// Returns if the given object is supported by this type. /// - public bool ObjectSupportsInterface(object @object); + bool ObjectSupportsInterface(object @object); /// /// Called to setup the property handlers on a given property. In this method, the handler will add listeners /// to the events that the surfaces that it cares about. /// - public void RegisterEvents(Com2PropertyDescriptor[]? properties); + void RegisterEvents(Com2PropertyDescriptor[]? properties); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ComboBox/ComboBox.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ComboBox/ComboBox.cs index d078054db08..95f65362b40 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ComboBox/ComboBox.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ComboBox/ComboBox.cs @@ -2052,7 +2052,7 @@ private bool InterceptAutoCompleteKeystroke(Message m) else { // Remove one character from matching text and rematch - MatchingText = MatchingText.Remove(MatchingText.Length - 1); + MatchingText = MatchingText[..^1]; SelectedIndex = FindString(MatchingText); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolStrip.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolStrip.cs index 040b4ff8ef4..4775f3e96ac 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolStrip.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolStrip.cs @@ -3933,7 +3933,7 @@ internal override void ReleaseUiaProvider(HWND handle) /// contains ToolStrip or ToolStripDropDown items to disconnect internal virtual void ReleaseToolStripItemsProviders(ToolStripItemCollection items) { - ToolStripItem[] itemsArray = items.Cast().ToArray(); + ToolStripItem[] itemsArray = [..items.Cast()]; foreach (ToolStripItem toolStripItem in itemsArray) { if (toolStripItem is ToolStripDropDownItem dropDownItem && dropDownItem.DropDownItems.Count > 0) diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolStripDropDown.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolStripDropDown.cs index 83777ba575b..573607e616c 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolStripDropDown.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolStripDropDown.cs @@ -1948,7 +1948,7 @@ private void DismissActiveDropDowns() } else { - List dropDowns = new(ActiveDropDowns); + List dropDowns = [..ActiveDropDowns]; // We can't iterate through the active dropdown collection // here as changing visibility changes the collection. diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Dialogs/TaskDialog/TaskDialogPage.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Dialogs/TaskDialog/TaskDialogPage.cs index 40be8a27feb..f8b6f7f43d7 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Dialogs/TaskDialog/TaskDialogPage.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Dialogs/TaskDialog/TaskDialogPage.cs @@ -868,10 +868,10 @@ internal void Bind( radioButtons.BoundPage = this; // Sort the buttons. - _boundCustomButtons = buttons.Where(e => !e.IsStandardButton).ToArray(); - _boundStandardButtonsByID = new Dictionary( - buttons.Where(e => e.IsStandardButton) - .Select(e => new KeyValuePair(e.ButtonID, e))); + _boundCustomButtons = [..buttons.Where(e => !e.IsStandardButton)]; + _boundStandardButtonsByID = buttons + .Where(e => e.IsStandardButton) + .ToDictionary(e => e.ButtonID); // Assign IDs to the buttons based on their index. defaultButtonID = 0;