diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ButtonBase.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ButtonBase.cs index accfbaa69a5..4b96956f71a 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/ButtonBase.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/ButtonBase.cs @@ -406,7 +406,7 @@ public int ImageIndex { } set { if (value < -1) { - throw new ArgumentOutOfRangeException(nameof(ImageIndex), string.Format(SR.InvalidLowBoundArgumentEx, "ImageIndex", (value).ToString(CultureInfo.CurrentCulture), (-1).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(ImageIndex), value, -1)); } if (imageIndex.Index != value) { if (value != -1) { diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ButtonInternal/ButtonBaseAdapter.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ButtonInternal/ButtonBaseAdapter.cs index daa7e81bc59..f66c378b35a 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/ButtonInternal/ButtonBaseAdapter.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/ButtonInternal/ButtonBaseAdapter.cs @@ -979,7 +979,7 @@ private int xCompose(Composition composition, int checkSize, int imageSize, int case Composition.AllCombined: return Math.Max(Math.Max(checkSize, imageSize), textSize); default: - Debug.Fail(string.Format(SR.InvalidArgument, "composition", composition.ToString())); + Debug.Fail(string.Format(SR.InvalidArgument, nameof(composition), composition.ToString())); return -7107; } } @@ -1006,7 +1006,7 @@ private int xDecompose(Composition composition, int checkSize, int imageSize, in case Composition.AllCombined: return proposedSize; default: - Debug.Fail(string.Format(SR.InvalidArgument, "composition", composition.ToString())); + Debug.Fail(string.Format(SR.InvalidArgument, nameof(composition), composition.ToString())); return -7109; } } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/CheckedListBox.cs b/src/System.Windows.Forms/src/System/Windows/Forms/CheckedListBox.cs index 424a74dd8da..1e89c4e2fe2 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/CheckedListBox.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/CheckedListBox.cs @@ -504,7 +504,7 @@ protected override ListBox.ObjectCollection CreateItemCollection() { public CheckState GetItemCheckState(int index) { if (index < 0 || index >= Items.Count) - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); return CheckedItems.GetCheckedState(index); } @@ -958,7 +958,7 @@ protected override void RefreshItems() { /// public void SetItemCheckState(int index, CheckState value) { if (index < 0 || index >= Items.Count) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } // valid values are 0-2 inclusive. if (!ClientUtils.IsEnumValid(value,(int)value, (int)CheckState.Unchecked, (int)CheckState.Indeterminate)){ diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Clipboard.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Clipboard.cs index 34d3bf1fa20..7a0b1a351b9 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Clipboard.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Clipboard.cs @@ -111,11 +111,11 @@ public static void SetDataObject(object data, bool copy, int retryTimes, int ret } if (retryTimes < 0) { - throw new ArgumentOutOfRangeException(nameof(retryTimes), string.Format(SR.InvalidLowBoundArgumentEx, "retryTimes", retryTimes.ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(retryTimes), retryTimes, string.Format(SR.InvalidLowBoundArgumentEx, nameof(retryTimes), retryTimes, 0)); } if (retryDelay < 0) { - throw new ArgumentOutOfRangeException(nameof(retryDelay), string.Format(SR.InvalidLowBoundArgumentEx, "retryDelay", retryDelay.ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(retryDelay), retryDelay, string.Format(SR.InvalidLowBoundArgumentEx, nameof(retryDelay), retryDelay, 0)); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ColumnHeader.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ColumnHeader.cs index b1c4e1415e8..f8b02e0b737 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/ColumnHeader.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/ColumnHeader.cs @@ -198,7 +198,7 @@ public int ImageIndex { } set { if (value < -1) { - throw new ArgumentOutOfRangeException(nameof(ImageIndex), string.Format(SR.InvalidLowBoundArgumentEx, "ImageIndex", (value).ToString(CultureInfo.CurrentCulture), (-1).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(ImageIndex), value, -1)); } if (imageIndexer.Index != value) { diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ComboBox.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ComboBox.cs index f42c2ef74a0..621bfbc936b 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/ComboBox.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/ComboBox.cs @@ -517,7 +517,7 @@ public int DropDownWidth { set { if (value < 1) { - throw new ArgumentOutOfRangeException(nameof(DropDownWidth), string.Format(SR.InvalidArgument, "DropDownWidth", (value).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidArgument, nameof(DropDownWidth), value)); } if (Properties.GetInteger(PropDropDownWidth) != value) { Properties.SetInteger(PropDropDownWidth, value); @@ -552,7 +552,7 @@ public int DropDownHeight { } set { if (value < 1) { - throw new ArgumentOutOfRangeException(nameof(DropDownHeight), string.Format(SR.InvalidArgument, "DropDownHeight", (value).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidArgument, nameof(DropDownHeight), value)); } if (Properties.GetInteger(PropDropDownHeight) != value) { Properties.SetInteger(PropDropDownHeight, value); @@ -722,7 +722,7 @@ public int ItemHeight { set { if (value < 1) { - throw new ArgumentOutOfRangeException(nameof(ItemHeight), string.Format(SR.InvalidArgument, "ItemHeight", (value).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidArgument, nameof(ItemHeight), value)); } ResetHeightCache(); @@ -788,7 +788,7 @@ public int MaxDropDownItems { } set { if (value < 1 || value > 100) { - throw new ArgumentOutOfRangeException(nameof(MaxDropDownItems), string.Format(SR.InvalidBoundArgument, "MaxDropDownItems", (value).ToString(CultureInfo.CurrentCulture), (1).ToString(CultureInfo.CurrentCulture), (100).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidBoundArgument, nameof(MaxDropDownItems), value, 1, 100)); } maxDropDownItems = (short)value; } @@ -1019,7 +1019,7 @@ public override int SelectedIndex { } if (value < -1 || value >= itemCount) { - throw new ArgumentOutOfRangeException(nameof(SelectedIndex), string.Format(SR.InvalidArgument, "SelectedIndex", (value).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidArgument, nameof(SelectedIndex), value)); } if (IsHandleCreated) { @@ -1146,7 +1146,7 @@ public int SelectionStart { } set { if (value < 0) { - throw new ArgumentOutOfRangeException(nameof(SelectionStart), string.Format(SR.InvalidArgument, "SelectionStart", value.ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidArgument, nameof(SelectionStart), value)); } Select(value, SelectionLength); } @@ -2115,7 +2115,7 @@ public int GetItemHeight(int index) { } if (index < 0 || itemsCollection == null || index >= itemsCollection.Count) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } if (IsHandleCreated) { @@ -3187,14 +3187,14 @@ private void SetAutoComplete(bool reset, bool recreate) { /// public void Select(int start, int length) { if (start < 0) { - throw new ArgumentOutOfRangeException(nameof(start), string.Format(SR.InvalidArgument, "start", start.ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(start), start, string.Format(SR.InvalidArgument, nameof(start), start)); } // the Length can be negative to support Selecting in the "reverse" direction.. int end = start + length; // but end cannot be negative... this means Length is far negative... if (end < 0) { - throw new ArgumentOutOfRangeException(nameof(length), string.Format(SR.InvalidArgument, "length", length.ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(length), length, string.Format(SR.InvalidArgument, nameof(length), length)); } SendMessage(NativeMethods.CB_SETEDITSEL, 0, NativeMethods.Util.MAKELPARAM(start, end)); @@ -3291,7 +3291,7 @@ internal override bool ShouldSerializeText() { public override string ToString() { string s = base.ToString(); - return s + ", Items.Count: " + ((itemsCollection == null) ? (0).ToString(CultureInfo.CurrentCulture) : itemsCollection.Count.ToString(CultureInfo.CurrentCulture)); + return s + ", Items.Count: " + ((itemsCollection == null) ? "0" : itemsCollection.Count.ToString(CultureInfo.CurrentCulture)); } /// @@ -4122,7 +4122,7 @@ internal void AddRangeInternal(IList items) { public virtual object this[int index] { get { if (index < 0 || index >= InnerList.Count) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } return InnerList[index]; @@ -4210,7 +4210,7 @@ public void Insert(int index, object item) { } if (index < 0 || index > InnerList.Count) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } // If the combo box is sorted, then nust treat this like an add @@ -4252,7 +4252,7 @@ public void RemoveAt(int index) { owner.CheckNoDataSource(); if (index < 0 || index >= InnerList.Count) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } if (owner.IsHandleCreated) { @@ -4289,7 +4289,7 @@ internal void SetItemInternal(int index, object value) { } if (index < 0 || index >= InnerList.Count) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } InnerList[index] = value; diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs index 52379575fb8..8402cc73c5a 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs @@ -3811,7 +3811,7 @@ public int TabIndex { } set { if (value < 0) { - throw new ArgumentOutOfRangeException(nameof(TabIndex), string.Format(SR.InvalidLowBoundArgumentEx, "TabIndex", value.ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(TabIndex), value, 0)); } if (tabIndex != value) { diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridView.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridView.cs index f31a9a40dfe..07672531a65 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridView.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridView.cs @@ -1765,7 +1765,7 @@ public int ColumnCount { if (value < 0) { - throw new ArgumentOutOfRangeException(nameof(ColumnCount), string.Format(SR.InvalidLowBoundArgumentEx, "ColumnCount", value.ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(ColumnCount), value, 0)); } if (this.DataSource != null) { @@ -1989,11 +1989,11 @@ public int ColumnHeadersHeight { if (value < minimumColumnHeadersHeight) { - throw new ArgumentOutOfRangeException(nameof(ColumnHeadersHeight), string.Format(SR.InvalidLowBoundArgumentEx, "ColumnHeadersHeight", (value).ToString(CultureInfo.CurrentCulture), (minimumColumnHeadersHeight).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), string.Format(SR.InvalidLowBoundArgumentEx, nameof(ColumnHeadersHeight), value, minimumColumnHeadersHeight)); } if (value > maxHeadersThickness) { - throw new ArgumentOutOfRangeException(nameof(ColumnHeadersHeight), string.Format(SR.InvalidHighBoundArgumentEx, "ColumnHeadersHeight", (value).ToString(CultureInfo.CurrentCulture), (maxHeadersThickness).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), string.Format(SR.InvalidHighBoundArgumentEx, nameof(ColumnHeadersHeight), value, maxHeadersThickness)); } if (this.ColumnHeadersHeightSizeMode == DataGridViewColumnHeadersHeightSizeMode.AutoSize) { @@ -3492,7 +3492,7 @@ public int HorizontalScrollingOffset // int widthNotVisible = this.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - this.layout.Data.Width; if (value < 0) { - throw new ArgumentOutOfRangeException(nameof(HorizontalScrollingOffset), string.Format(SR.InvalidLowBoundArgumentEx, "HorizontalScrollingOffset", (value).ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(HorizontalScrollingOffset), value, 0)); } // Intentionally ignoring the out of range situation. // else if (value > widthNotVisible && widthNotVisible > 0) @@ -4021,14 +4021,14 @@ public int RowCount { if (value < 1) { - throw new ArgumentOutOfRangeException(nameof(RowCount), string.Format(SR.InvalidLowBoundArgumentEx, "RowCount", value.ToString(CultureInfo.CurrentCulture), (1).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(RowCount), value, 1)); } } else { if (value < 0) { - throw new ArgumentOutOfRangeException(nameof(RowCount), string.Format(SR.InvalidLowBoundArgumentEx, "RowCount", value.ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(RowCount), value, 0)); } } if (this.DataSource != null) @@ -4279,12 +4279,13 @@ public int RowHeadersWidth { if (value < minimumRowHeadersWidth) { - throw new ArgumentOutOfRangeException(nameof(RowHeadersWidth), string.Format(SR.InvalidLowBoundArgumentEx, "RowHeadersWidth", (value).ToString(CultureInfo.CurrentCulture), (minimumRowHeadersWidth).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(RowHeadersWidth), value, minimumRowHeadersWidth)); } if (value > maxHeadersThickness) { - throw new ArgumentOutOfRangeException(nameof(RowHeadersWidth), string.Format(SR.InvalidHighBoundArgumentEx, "RowHeadersWidth", (value).ToString(CultureInfo.CurrentCulture), (maxHeadersThickness).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidHighBoundArgumentEx, nameof(RowHeadersWidth), value, maxHeadersThickness)); } + if (this.RowHeadersWidthSizeMode != DataGridViewRowHeadersWidthSizeMode.EnableResizing && this.RowHeadersWidthSizeMode != DataGridViewRowHeadersWidthSizeMode.DisableResizing) { diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewBand.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewBand.cs index 3f69bc33742..732a658b142 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewBand.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewBand.cs @@ -2,96 +2,70 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.ComponentModel; +using System.Diagnostics; +using System.Drawing; +using System.Globalization; +using System.Text; + namespace System.Windows.Forms { - using System.ComponentModel; - using System.Diagnostics; - using System.Drawing; - using System.Text; - using System; - using System.Globalization; - - /// /// - /// Identifies a band or column in the dataGridView. + /// Identifies a band or column in the dataGridView. /// public class DataGridViewBand : DataGridViewElement, ICloneable, IDisposable { - private static readonly int PropContextMenuStrip = PropertyStore.CreateKey(); - private static readonly int PropDefaultCellStyle = PropertyStore.CreateKey(); - private static readonly int PropDefaultHeaderCellType = PropertyStore.CreateKey(); - private static readonly int PropDividerThickness = PropertyStore.CreateKey(); - private static readonly int PropHeaderCell = PropertyStore.CreateKey(); - private static readonly int PropUserData = PropertyStore.CreateKey(); - - internal const int minBandThickness = 2; - internal const int maxBandThickness = 65536; - - private PropertyStore propertyStore; // Contains all properties that are not always set. - private int thickness, cachedThickness; - private int minimumThickness; - private int bandIndex; + private static readonly int s_propContextMenuStrip = PropertyStore.CreateKey(); + private static readonly int s_propDefaultCellStyle = PropertyStore.CreateKey(); + private static readonly int s_propDefaultHeaderCellType = PropertyStore.CreateKey(); + private static readonly int s_propDividerThickness = PropertyStore.CreateKey(); + private static readonly int s_propHeaderCell = PropertyStore.CreateKey(); + private static readonly int s_propUserData = PropertyStore.CreateKey(); + + internal const int MinBandThickness = 2; + internal const int MaxBandThickness = 65536; + + // Contains all properties that are not always set. + private PropertyStore _propertyStore; + private int _thickness; + private int _minimumThickness; + private int _bandIndex; internal bool _bandIsRow; - /// /// - /// - /// Initializes a new instance of the class. - /// + /// Initializes a new instance of the class. /// internal DataGridViewBand() { - this.propertyStore = new PropertyStore(); - this.bandIndex = -1; - } - - /// - ~DataGridViewBand() - { - Dispose(false); + _propertyStore = new PropertyStore(); + _bandIndex = -1; } - internal int CachedThickness - { - get - { - return this.cachedThickness; - } - set - { - this.cachedThickness = value; - } - } + ~DataGridViewBand() => Dispose(false); + + internal int CachedThickness { get; set; } - /// - [ - DefaultValue(null) - ] + [DefaultValue(null)] public virtual ContextMenuStrip ContextMenuStrip { get { - if (this._bandIsRow) + if (_bandIsRow) { - return ((DataGridViewRow) this).GetContextMenuStrip(this.Index); + return ((DataGridViewRow)this).GetContextMenuStrip(Index); } - return this.ContextMenuStripInternal; - } - set - { - this.ContextMenuStripInternal = value; + + return ContextMenuStripInternal; } + set => ContextMenuStripInternal = value; } internal ContextMenuStrip ContextMenuStripInternal { - get - { - return (ContextMenuStrip)this.Properties.GetObject(PropContextMenuStrip); - } + get => (ContextMenuStrip)Properties.GetObject(s_propContextMenuStrip); set { - ContextMenuStrip oldValue = (ContextMenuStrip)this.Properties.GetObject(PropContextMenuStrip); + ContextMenuStrip oldValue = (ContextMenuStrip)Properties.GetObject(s_propContextMenuStrip); if (oldValue != value) { EventHandler disposedHandler = new EventHandler(DetachContextMenuStrip); @@ -99,115 +73,98 @@ internal ContextMenuStrip ContextMenuStripInternal { oldValue.Disposed -= disposedHandler; } - this.Properties.SetObject(PropContextMenuStrip, value); + + Properties.SetObject(s_propContextMenuStrip, value); if (value != null) { value.Disposed += disposedHandler; } - if (this.DataGridView != null) - { - this.DataGridView.OnBandContextMenuStripChanged(this); - } + + DataGridView?.OnBandContextMenuStripChanged(this); } } } - /// - [ - Browsable(false) - ] + [Browsable(false)] public virtual DataGridViewCellStyle DefaultCellStyle { get { - DataGridViewCellStyle dgvcs = (DataGridViewCellStyle)this.Properties.GetObject(PropDefaultCellStyle); - if (dgvcs == null) + DataGridViewCellStyle style = (DataGridViewCellStyle)Properties.GetObject(s_propDefaultCellStyle); + if (style == null) { - dgvcs = new DataGridViewCellStyle(); - dgvcs.AddScope(this.DataGridView, - this._bandIsRow ? DataGridViewCellStyleScopes.Row : DataGridViewCellStyleScopes.Column); - this.Properties.SetObject(PropDefaultCellStyle, dgvcs); + style = new DataGridViewCellStyle(); + style.AddScope(DataGridView, _bandIsRow ? DataGridViewCellStyleScopes.Row : DataGridViewCellStyleScopes.Column); + Properties.SetObject(s_propDefaultCellStyle, style); } - return dgvcs; + + return style; } set { - DataGridViewCellStyle dgvcs = null; - if (this.HasDefaultCellStyle) + DataGridViewCellStyle style = null; + if (HasDefaultCellStyle) { - dgvcs = this.DefaultCellStyle; - dgvcs.RemoveScope(this._bandIsRow ? DataGridViewCellStyleScopes.Row : DataGridViewCellStyleScopes.Column); + style = DefaultCellStyle; + style.RemoveScope(_bandIsRow ? DataGridViewCellStyleScopes.Row : DataGridViewCellStyleScopes.Column); } - if (value != null || this.Properties.ContainsObject(PropDefaultCellStyle)) + if (value != null || Properties.ContainsObject(s_propDefaultCellStyle)) { - if (value != null) - { - value.AddScope(this.DataGridView, - this._bandIsRow ? DataGridViewCellStyleScopes.Row : DataGridViewCellStyleScopes.Column); - } - this.Properties.SetObject(PropDefaultCellStyle, value); + value?.AddScope(DataGridView, _bandIsRow ? DataGridViewCellStyleScopes.Row : DataGridViewCellStyleScopes.Column); + Properties.SetObject(s_propDefaultCellStyle, value); } - if (((dgvcs != null && value == null) || - (dgvcs == null && value != null) || - (dgvcs != null && value != null && !dgvcs.Equals(this.DefaultCellStyle))) && this.DataGridView != null) + + if (DataGridView != null && + (style != null ^ value != null) || + (style != null && value != null && !style.Equals(DefaultCellStyle))) { - this.DataGridView.OnBandDefaultCellStyleChanged(this); + DataGridView.OnBandDefaultCellStyleChanged(this); } } } - /// - [ - Browsable(false) - ] + [Browsable(false)] public Type DefaultHeaderCellType { get { - Type dhct = (Type)this.Properties.GetObject(PropDefaultHeaderCellType); - if (dhct == null) + Type type = (Type)Properties.GetObject(s_propDefaultHeaderCellType); + if (type != null) { - if (this._bandIsRow) - { - dhct = typeof(System.Windows.Forms.DataGridViewRowHeaderCell); - } - else - { - dhct = typeof(System.Windows.Forms.DataGridViewColumnHeaderCell); - } + return type; + } + + if (_bandIsRow) + { + return typeof(DataGridViewRowHeaderCell); + } + else + { + return typeof(DataGridViewColumnHeaderCell); } - return dhct; } set { - if (value != null || this.Properties.ContainsObject(PropDefaultHeaderCellType)) + if (value != null || Properties.ContainsObject(s_propDefaultHeaderCellType)) { - if (Type.GetType("System.Windows.Forms.DataGridViewHeaderCell").IsAssignableFrom(value)) - { - this.Properties.SetObject(PropDefaultHeaderCellType, value); - } - else + if (!typeof(DataGridViewHeaderCell).IsAssignableFrom(value)) { - throw new ArgumentException(string.Format(SR.DataGridView_WrongType, "DefaultHeaderCellType", "System.Windows.Forms.DataGridViewHeaderCell")); + throw new ArgumentException(string.Format(SR.DataGridView_WrongType, nameof(DefaultHeaderCellType), "System.Windows.Forms.DataGridViewHeaderCell"), nameof(value)); } + + Properties.SetObject(s_propDefaultHeaderCellType, value); } } } - /// - [ - Browsable(false), - DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) - ] + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public virtual bool Displayed { get { - Debug.Assert(!this._bandIsRow); - bool displayed = (this.State & DataGridViewElementStates.Displayed) != 0; - // Only attached and visible columns can be displayed. - // Debug.Assert(!displayed || (this.DataGridView != null && this.DataGridView.Visible && this.Visible)); - return displayed; + Debug.Assert(!_bandIsRow); + return (State & DataGridViewElementStates.Displayed) != 0; } } @@ -215,16 +172,16 @@ internal bool DisplayedInternal { set { - Debug.Assert(value != this.Displayed); + Debug.Assert(value != Displayed); if (value) { - this.StateInternal = this.State | DataGridViewElementStates.Displayed; + StateInternal = State | DataGridViewElementStates.Displayed; } else { - this.StateInternal = this.State & ~DataGridViewElementStates.Displayed; + StateInternal = State & ~DataGridViewElementStates.Displayed; } - if (this.DataGridView != null) + if (DataGridView != null) { OnStateChanged(DataGridViewElementStates.Displayed); } @@ -235,148 +192,128 @@ internal int DividerThickness { get { - bool found; - int dividerThickness = this.Properties.GetInteger(PropDividerThickness, out found); + int dividerThickness = Properties.GetInteger(s_propDividerThickness, out bool found); return found ? dividerThickness : 0; } set { if (value < 0) { - if (this._bandIsRow) + if (_bandIsRow) { - throw new ArgumentOutOfRangeException("DividerHeight", string.Format(SR.InvalidLowBoundArgumentEx, "DividerHeight", (value).ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), string.Format(SR.InvalidLowBoundArgumentEx, nameof(DataGridViewRow.DividerHeight), value, 0)); } else { - throw new ArgumentOutOfRangeException("DividerWidth", string.Format(SR.InvalidLowBoundArgumentEx, "DividerWidth", (value).ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), string.Format(SR.InvalidLowBoundArgumentEx, nameof(DataGridViewColumn.DividerWidth), value, 0)); } } - if (value > maxBandThickness) + if (value > MaxBandThickness) { - if (this._bandIsRow) + if (_bandIsRow) { - throw new ArgumentOutOfRangeException("DividerHeight", string.Format(SR.InvalidHighBoundArgumentEx, "DividerHeight", (value).ToString(CultureInfo.CurrentCulture), (maxBandThickness).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), string.Format(SR.InvalidHighBoundArgumentEx, nameof(DataGridViewRow.DividerHeight), value, MaxBandThickness)); } else { - throw new ArgumentOutOfRangeException("DividerWidth", string.Format(SR.InvalidHighBoundArgumentEx, "DividerWidth", (value).ToString(CultureInfo.CurrentCulture), (maxBandThickness).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), string.Format(SR.InvalidHighBoundArgumentEx, nameof(DataGridViewColumn.DividerWidth), value, MaxBandThickness)); } } - if (value != this.DividerThickness) + + if (value != DividerThickness) { - this.Properties.SetInteger(PropDividerThickness, (int)value); - if (this.DataGridView != null) - { - this.DataGridView.OnBandDividerThicknessChanged(this); - } + Properties.SetInteger(s_propDividerThickness, value); + DataGridView?.OnBandDividerThicknessChanged(this); } } } - /// - [ - DefaultValue(false), - ] + [DefaultValue(false)] public virtual bool Frozen { get { - Debug.Assert(!this._bandIsRow); - return (this.State & DataGridViewElementStates.Frozen) != 0; + Debug.Assert(!_bandIsRow); + return (State & DataGridViewElementStates.Frozen) != 0; } set { - if (((this.State & DataGridViewElementStates.Frozen) != 0) != value) + if (((State & DataGridViewElementStates.Frozen) != 0) != value) { OnStateChanging(DataGridViewElementStates.Frozen); if (value) { - this.StateInternal = this.State | DataGridViewElementStates.Frozen; + StateInternal = State | DataGridViewElementStates.Frozen; } else { - this.StateInternal = this.State & ~DataGridViewElementStates.Frozen; + StateInternal = State & ~DataGridViewElementStates.Frozen; } OnStateChanged(DataGridViewElementStates.Frozen); } } } - /// - [ - Browsable(false) - ] + [Browsable(false)] public bool HasDefaultCellStyle { - get - { - return this.Properties.ContainsObject(PropDefaultCellStyle) && this.Properties.GetObject(PropDefaultCellStyle) != null; - } + get => Properties.ContainsObject(s_propDefaultCellStyle) && Properties.GetObject(s_propDefaultCellStyle) != null; } internal bool HasDefaultHeaderCellType { - get - { - return this.Properties.ContainsObject(PropDefaultHeaderCellType) && this.Properties.GetObject(PropDefaultHeaderCellType) != null; - } + get => Properties.ContainsObject(s_propDefaultHeaderCellType) && Properties.GetObject(s_propDefaultHeaderCellType) != null; } internal bool HasHeaderCell { - get - { - return this.Properties.ContainsObject(PropHeaderCell) && this.Properties.GetObject(PropHeaderCell) != null; - } + get => Properties.ContainsObject(s_propHeaderCell) && Properties.GetObject(s_propHeaderCell) != null; } - /// - [ - Browsable(false), - DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) - ] + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] protected DataGridViewHeaderCell HeaderCellCore { get { - DataGridViewHeaderCell headerCell = (DataGridViewHeaderCell)this.Properties.GetObject(PropHeaderCell); + DataGridViewHeaderCell headerCell = (DataGridViewHeaderCell)Properties.GetObject(s_propHeaderCell); if (headerCell == null) { - Type cellType = this.DefaultHeaderCellType; + Type cellType = DefaultHeaderCellType; - headerCell = (DataGridViewHeaderCell) Activator.CreateInstance(cellType); - headerCell.DataGridViewInternal = this.DataGridView; - if (this._bandIsRow) + headerCell = (DataGridViewHeaderCell)Activator.CreateInstance(cellType); + headerCell.DataGridViewInternal = DataGridView; + if (_bandIsRow) { headerCell.OwningRowInternal = (DataGridViewRow)this; // may be a shared row - this.Properties.SetObject(PropHeaderCell, headerCell); + Properties.SetObject(s_propHeaderCell, headerCell); } else { DataGridViewColumn dataGridViewColumn = this as DataGridViewColumn; headerCell.OwningColumnInternal = dataGridViewColumn; // Set the headerCell in the property store before setting the SortOrder. - this.Properties.SetObject(PropHeaderCell, headerCell); - if (this.DataGridView != null && this.DataGridView.SortedColumn == dataGridViewColumn) + Properties.SetObject(s_propHeaderCell, headerCell); + if (DataGridView != null && DataGridView.SortedColumn == dataGridViewColumn) { DataGridViewColumnHeaderCell dataGridViewColumnHeaderCell = headerCell as DataGridViewColumnHeaderCell; Debug.Assert(dataGridViewColumnHeaderCell != null); - dataGridViewColumnHeaderCell.SortGlyphDirection = this.DataGridView.SortOrder; + dataGridViewColumnHeaderCell.SortGlyphDirection = DataGridView.SortOrder; } } } + return headerCell; } set { - DataGridViewHeaderCell headerCell = (DataGridViewHeaderCell)this.Properties.GetObject(PropHeaderCell); - if (value != null || this.Properties.ContainsObject(PropHeaderCell)) + DataGridViewHeaderCell headerCell = (DataGridViewHeaderCell)Properties.GetObject(s_propHeaderCell); + if (value != null || Properties.ContainsObject(s_propHeaderCell)) { if (headerCell != null) { headerCell.DataGridViewInternal = null; - if (this._bandIsRow) + if (_bandIsRow) { headerCell.OwningRowInternal = null; } @@ -389,12 +326,13 @@ protected DataGridViewHeaderCell HeaderCellCore if (value != null) { - if (this._bandIsRow) + if (_bandIsRow) { if (!(value is DataGridViewRowHeaderCell)) { - throw new ArgumentException(string.Format(SR.DataGridView_WrongType, "HeaderCell", "System.Windows.Forms.DataGridViewRowHeaderCell")); + throw new ArgumentException(string.Format(SR.DataGridView_WrongType, nameof(DataGridViewRow.HeaderCell), "System.Windows.Forms.DataGridViewRowHeaderCell"), nameof(value)); } + // A HeaderCell can only be used by one band. if (value.OwningRow != null) { @@ -408,8 +346,9 @@ protected DataGridViewHeaderCell HeaderCellCore DataGridViewColumnHeaderCell dataGridViewColumnHeaderCell = value as DataGridViewColumnHeaderCell; if (dataGridViewColumnHeaderCell == null) { - throw new ArgumentException(string.Format(SR.DataGridView_WrongType, "HeaderCell", "System.Windows.Forms.DataGridViewColumnHeaderCell")); + throw new ArgumentException(string.Format(SR.DataGridView_WrongType, nameof(DataGridViewColumn.HeaderCell), "System.Windows.Forms.DataGridViewColumnHeaderCell"), nameof(value)); } + // A HeaderCell can only be used by one band. if (value.OwningColumn != null) { @@ -420,132 +359,92 @@ protected DataGridViewHeaderCell HeaderCellCore value.OwningColumnInternal = (DataGridViewColumn)this; } Debug.Assert(value.DataGridView == null); - value.DataGridViewInternal = this.DataGridView; + value.DataGridViewInternal = DataGridView; } - this.Properties.SetObject(PropHeaderCell, value); + Properties.SetObject(s_propHeaderCell, value); } - if (((value == null && headerCell != null) || (value != null && headerCell == null) || (value != null && headerCell != null && !headerCell.Equals(value))) && this.DataGridView != null) + if (((value == null && headerCell != null) || (value != null && headerCell == null) || (value != null && headerCell != null && !headerCell.Equals(value))) && DataGridView != null) { - this.DataGridView.OnBandHeaderCellChanged(this); + DataGridView.OnBandHeaderCellChanged(this); } } } - /// - /// - /// - /// - [ - Browsable(false) - ] - public int Index - { - get - { - return this.bandIndex; - } - } + [Browsable(false)] + public int Index => _bandIndex; internal int IndexInternal { - set - { - this.bandIndex = value; - } + set => _bandIndex = value; } - /// - [ - Browsable(false) - ] - public virtual DataGridViewCellStyle InheritedStyle - { - get - { - return null; - } - } + [Browsable(false)] + public virtual DataGridViewCellStyle InheritedStyle => null; - /// - protected bool IsRow - { - get - { - return this._bandIsRow; - } - } + protected bool IsRow => _bandIsRow; internal int MinimumThickness { get { - if (this._bandIsRow && this.bandIndex > -1) + if (_bandIsRow && _bandIndex > -1) { - int height, minimumHeight; - GetHeightInfo(this.bandIndex, out height, out minimumHeight); + GetHeightInfo(_bandIndex, out int height, out int minimumHeight); return minimumHeight; } - return this.minimumThickness; + + return _minimumThickness; } set { - if (this.minimumThickness != value) + if (_minimumThickness != value) { - if (value < minBandThickness) + if (value < MinBandThickness) { - if (this._bandIsRow) + if (_bandIsRow) { - throw new ArgumentOutOfRangeException("MinimumHeight", value, string.Format(SR.DataGridViewBand_MinimumHeightSmallerThanOne, (DataGridViewBand.minBandThickness).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.DataGridViewBand_MinimumHeightSmallerThanOne, DataGridViewBand.MinBandThickness)); } else { - throw new ArgumentOutOfRangeException("MinimumWidth", value, string.Format(SR.DataGridViewBand_MinimumWidthSmallerThanOne, (DataGridViewBand.minBandThickness).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.DataGridViewBand_MinimumWidthSmallerThanOne, DataGridViewBand.MinBandThickness)); } } - if (this.Thickness < value) + + if (Thickness < value) { // Force the new minimum width on potential auto fill column. - if (this.DataGridView != null && !this._bandIsRow) + if (DataGridView != null && !_bandIsRow) { - this.DataGridView.OnColumnMinimumWidthChanging((DataGridViewColumn)this, value); + DataGridView.OnColumnMinimumWidthChanging((DataGridViewColumn)this, value); } - this.Thickness = value; - } - this.minimumThickness = value; - if (this.DataGridView != null) - { - this.DataGridView.OnBandMinimumThicknessChanged(this); + + Thickness = value; } + + _minimumThickness = value; + DataGridView?.OnBandMinimumThicknessChanged(this); } } } - internal PropertyStore Properties - { - get - { - return this.propertyStore; - } - } + internal PropertyStore Properties => _propertyStore; - /// - [ - DefaultValue(false) - ] + [DefaultValue(false)] public virtual bool ReadOnly { get { - Debug.Assert(!this._bandIsRow); - return ((this.State & DataGridViewElementStates.ReadOnly) != 0 || - (this.DataGridView != null && this.DataGridView.ReadOnly)); + Debug.Assert(!_bandIsRow); + return ((State & DataGridViewElementStates.ReadOnly) != 0 || + (DataGridView != null && DataGridView.ReadOnly)); } set { - if (this.DataGridView != null) + if (DataGridView != null) { - if (this.DataGridView.ReadOnly) + if (DataGridView.ReadOnly) { // if (!value): Trying to make a band read-write when the whole grid is read-only. // if (value): Trying to make a band read-only when the whole grid is read-only. @@ -554,31 +453,32 @@ public virtual bool ReadOnly } // this may trigger a call to set_ReadOnlyInternal - if (this._bandIsRow) + if (_bandIsRow) { - if (this.bandIndex == -1) + if (_bandIndex == -1) { - throw new InvalidOperationException(string.Format(SR.DataGridView_InvalidPropertySetOnSharedRow, "ReadOnly")); + throw new InvalidOperationException(string.Format(SR.DataGridView_InvalidPropertySetOnSharedRow, nameof(ReadOnly))); } + OnStateChanging(DataGridViewElementStates.ReadOnly); - this.DataGridView.SetReadOnlyRowCore(this.bandIndex, value); + DataGridView.SetReadOnlyRowCore(_bandIndex, value); } else { - Debug.Assert(this.bandIndex >= 0); + Debug.Assert(_bandIndex >= 0); OnStateChanging(DataGridViewElementStates.ReadOnly); - this.DataGridView.SetReadOnlyColumnCore(this.bandIndex, value); + DataGridView.SetReadOnlyColumnCore(_bandIndex, value); } } else { - if (((this.State & DataGridViewElementStates.ReadOnly) != 0) != value) + if (((State & DataGridViewElementStates.ReadOnly) != 0) != value) { if (value) { - if (this._bandIsRow) + if (_bandIsRow) { - foreach (DataGridViewCell dataGridViewCell in ((DataGridViewRow) this).Cells) + foreach (DataGridViewCell dataGridViewCell in ((DataGridViewRow)this).Cells) { if (dataGridViewCell.ReadOnly) { @@ -586,11 +486,11 @@ public virtual bool ReadOnly } } } - this.StateInternal = this.State | DataGridViewElementStates.ReadOnly; + StateInternal = State | DataGridViewElementStates.ReadOnly; } else { - this.StateInternal = this.State & ~DataGridViewElementStates.ReadOnly; + StateInternal = State & ~DataGridViewElementStates.ReadOnly; } } } @@ -601,41 +501,37 @@ internal bool ReadOnlyInternal { set { - Debug.Assert(value != this.ReadOnly); + Debug.Assert(value != ReadOnly); if (value) { - this.StateInternal = this.State | DataGridViewElementStates.ReadOnly; + StateInternal = State | DataGridViewElementStates.ReadOnly; } else { - this.StateInternal = this.State & ~DataGridViewElementStates.ReadOnly; + StateInternal = State & ~DataGridViewElementStates.ReadOnly; } - Debug.Assert(this.DataGridView != null); + + Debug.Assert(DataGridView != null); OnStateChanged(DataGridViewElementStates.ReadOnly); } } - /// - [ - Browsable(true) - ] + [Browsable(true)] public virtual DataGridViewTriState Resizable { get { - Debug.Assert(!this._bandIsRow); - if ((this.State & DataGridViewElementStates.ResizableSet) != 0) + Debug.Assert(!_bandIsRow); + if ((State & DataGridViewElementStates.ResizableSet) != 0) { - return ((this.State & DataGridViewElementStates.Resizable) != 0) ? DataGridViewTriState.True : DataGridViewTriState.False; + return ((State & DataGridViewElementStates.Resizable) != 0) ? DataGridViewTriState.True : DataGridViewTriState.False; } - if (this.DataGridView != null) - { - return this.DataGridView.AllowUserToResizeColumns ? DataGridViewTriState.True : DataGridViewTriState.False; - } - else + if (DataGridView == null) { return DataGridViewTriState.NotSet; } + + return DataGridView.AllowUserToResizeColumns ? DataGridViewTriState.True : DataGridViewTriState.False; } set { @@ -644,74 +540,72 @@ public virtual DataGridViewTriState Resizable throw new InvalidEnumArgumentException(nameof(value), (int)value, typeof(DataGridViewTriState)); } - DataGridViewTriState oldResizable = this.Resizable; + DataGridViewTriState oldResizable = Resizable; if (value == DataGridViewTriState.NotSet) { - this.StateInternal = this.State & ~DataGridViewElementStates.ResizableSet; + StateInternal = State & ~DataGridViewElementStates.ResizableSet; } else { - this.StateInternal = this.State | DataGridViewElementStates.ResizableSet; - if (((this.State & DataGridViewElementStates.Resizable) != 0) != (value == DataGridViewTriState.True)) + StateInternal = State | DataGridViewElementStates.ResizableSet; + if (((State & DataGridViewElementStates.Resizable) != 0) != (value == DataGridViewTriState.True)) { if (value == DataGridViewTriState.True) { - this.StateInternal = this.State | DataGridViewElementStates.Resizable; + StateInternal = State | DataGridViewElementStates.Resizable; } else { - this.StateInternal = this.State & ~DataGridViewElementStates.Resizable; + StateInternal = State & ~DataGridViewElementStates.Resizable; } } } - if (oldResizable != this.Resizable) + + if (oldResizable != Resizable) { OnStateChanged(DataGridViewElementStates.Resizable); } } } - /// - [ - Browsable(false), - DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) - ] + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public virtual bool Selected { get { - Debug.Assert(!this._bandIsRow); - return (this.State & DataGridViewElementStates.Selected) != 0; + Debug.Assert(!_bandIsRow); + return (State & DataGridViewElementStates.Selected) != 0; } set { - if (this.DataGridView != null) + if (DataGridView != null) { // this may trigger a call to set_SelectedInternal - if (this._bandIsRow) + if (_bandIsRow) { - if (this.bandIndex == -1) + if (_bandIndex == -1) { - throw new InvalidOperationException(string.Format(SR.DataGridView_InvalidPropertySetOnSharedRow, "Selected")); + throw new InvalidOperationException(string.Format(SR.DataGridView_InvalidPropertySetOnSharedRow, nameof(Selected))); } - if (this.DataGridView.SelectionMode == DataGridViewSelectionMode.FullRowSelect || this.DataGridView.SelectionMode == DataGridViewSelectionMode.RowHeaderSelect) + if (DataGridView.SelectionMode == DataGridViewSelectionMode.FullRowSelect || DataGridView.SelectionMode == DataGridViewSelectionMode.RowHeaderSelect) { - this.DataGridView.SetSelectedRowCoreInternal(this.bandIndex, value); + DataGridView.SetSelectedRowCoreInternal(_bandIndex, value); } } else { - Debug.Assert(this.bandIndex >= 0); - if (this.DataGridView.SelectionMode == DataGridViewSelectionMode.FullColumnSelect || this.DataGridView.SelectionMode == DataGridViewSelectionMode.ColumnHeaderSelect) + Debug.Assert(_bandIndex >= 0); + if (DataGridView.SelectionMode == DataGridViewSelectionMode.FullColumnSelect || DataGridView.SelectionMode == DataGridViewSelectionMode.ColumnHeaderSelect) { - this.DataGridView.SetSelectedColumnCoreInternal(this.bandIndex, value); + DataGridView.SetSelectedColumnCoreInternal(_bandIndex, value); } } } else if (value) { // We do not allow the selection of a band before it gets added to the dataGridView. - throw new InvalidOperationException(string.Format(SR.DataGridViewBand_CannotSelect)); + throw new InvalidOperationException(SR.DataGridViewBand_CannotSelect); } } } @@ -720,38 +614,33 @@ internal bool SelectedInternal { set { - Debug.Assert(value != this.Selected); + Debug.Assert(value != Selected); if (value) { - this.StateInternal = this.State | DataGridViewElementStates.Selected; + StateInternal = State | DataGridViewElementStates.Selected; } else { - this.StateInternal = this.State & ~DataGridViewElementStates.Selected; + StateInternal = State & ~DataGridViewElementStates.Selected; } - if (this.DataGridView != null) + + if (DataGridView != null) { OnStateChanged(DataGridViewElementStates.Selected); } } } - /// - [ - Browsable(false), - DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) - ] + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public object Tag { - get - { - return Properties.GetObject(PropUserData); - } + get => Properties.GetObject(s_propUserData); set { - if (value != null || this.Properties.ContainsObject(PropUserData)) + if (value != null || Properties.ContainsObject(s_propUserData)) { - Properties.SetObject(PropUserData, value); + Properties.SetObject(s_propUserData, value); } } } @@ -760,189 +649,176 @@ internal int Thickness { get { - if (this._bandIsRow && this.bandIndex > -1) + if (_bandIsRow && _bandIndex > -1) { - int height, minimumHeight; - GetHeightInfo(this.bandIndex, out height, out minimumHeight); + GetHeightInfo(_bandIndex, out int height, out int minimumHeight); return height; } - return this.thickness; + + return _thickness; } set { - int minimumThickness = this.MinimumThickness; + int minimumThickness = MinimumThickness; if (value < minimumThickness) { value = minimumThickness; } - if (value > maxBandThickness) + if (value > MaxBandThickness) { - if (this._bandIsRow) + if (_bandIsRow) { - throw new ArgumentOutOfRangeException("Height", string.Format(SR.InvalidHighBoundArgumentEx, "Height", (value).ToString(CultureInfo.CurrentCulture), (maxBandThickness).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), string.Format(SR.InvalidHighBoundArgumentEx, nameof(DataGridViewRow.Height), value, MaxBandThickness)); } else { - throw new ArgumentOutOfRangeException("Width", string.Format(SR.InvalidHighBoundArgumentEx, "Width", (value).ToString(CultureInfo.CurrentCulture), (maxBandThickness).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), string.Format(SR.InvalidHighBoundArgumentEx, nameof(DataGridViewColumn.Width), value, MaxBandThickness)); } } + bool setThickness = true; - if (this._bandIsRow) + if (_bandIsRow) { - if (this.DataGridView != null && this.DataGridView.AutoSizeRowsMode != DataGridViewAutoSizeRowsMode.None) + if (DataGridView != null && DataGridView.AutoSizeRowsMode != DataGridViewAutoSizeRowsMode.None) { - this.cachedThickness = value; + CachedThickness = value; setThickness = false; } } else { - DataGridViewColumn dataGridViewColumn = (DataGridViewColumn) this; + DataGridViewColumn dataGridViewColumn = (DataGridViewColumn)this; DataGridViewAutoSizeColumnMode inheritedAutoSizeMode = dataGridViewColumn.InheritedAutoSizeMode; if (inheritedAutoSizeMode != DataGridViewAutoSizeColumnMode.Fill && inheritedAutoSizeMode != DataGridViewAutoSizeColumnMode.None && inheritedAutoSizeMode != DataGridViewAutoSizeColumnMode.NotSet) { - this.cachedThickness = value; + CachedThickness = value; setThickness = false; } - else if (inheritedAutoSizeMode == DataGridViewAutoSizeColumnMode.Fill && this.DataGridView != null) + else if (inheritedAutoSizeMode == DataGridViewAutoSizeColumnMode.Fill && DataGridView != null) { if (dataGridViewColumn.Visible) { - IntPtr handle = this.DataGridView.Handle; - this.DataGridView.AdjustFillingColumn(dataGridViewColumn, value); + IntPtr handle = DataGridView.Handle; + DataGridView.AdjustFillingColumn(dataGridViewColumn, value); setThickness = false; } } } - if (setThickness && this.thickness != value) + if (setThickness && _thickness != value) { - if (this.DataGridView != null) - { - this.DataGridView.OnBandThicknessChanging(); - } - this.ThicknessInternal = value; + DataGridView?.OnBandThicknessChanging(); + ThicknessInternal = value; } } } internal int ThicknessInternal { - get - { - return this.thickness; - } + get => _thickness; set { - Debug.Assert(this.thickness != value); - Debug.Assert(value >= this.minimumThickness); - Debug.Assert(value <= maxBandThickness); + Debug.Assert(_thickness != value); + Debug.Assert(value >= _minimumThickness); + Debug.Assert(value <= MaxBandThickness); - this.thickness = value; - if (this.DataGridView != null) - { - this.DataGridView.OnBandThicknessChanged(this); - } + _thickness = value; + DataGridView?.OnBandThicknessChanged(this); } } - /// - [ - DefaultValue(true), - ] + [DefaultValue(true)] public virtual bool Visible { get { - Debug.Assert(!this._bandIsRow); - return (this.State & DataGridViewElementStates.Visible) != 0; + Debug.Assert(!_bandIsRow); + return (State & DataGridViewElementStates.Visible) != 0; } set { - if (((this.State & DataGridViewElementStates.Visible) != 0) != value) + if (((State & DataGridViewElementStates.Visible) != 0) != value) { - if (this.DataGridView != null && - this._bandIsRow && - this.DataGridView.NewRowIndex != -1 && - this.DataGridView.NewRowIndex == this.bandIndex && + if (DataGridView != null && + _bandIsRow && + DataGridView.NewRowIndex != -1 && + DataGridView.NewRowIndex == _bandIndex && !value) { // the 'new' row cannot be made invisble. - throw new InvalidOperationException(string.Format(SR.DataGridViewBand_NewRowCannotBeInvisible)); + throw new InvalidOperationException(SR.DataGridViewBand_NewRowCannotBeInvisible); } + OnStateChanging(DataGridViewElementStates.Visible); if (value) { - this.StateInternal = this.State | DataGridViewElementStates.Visible; + StateInternal = State | DataGridViewElementStates.Visible; } else { - this.StateInternal = this.State & ~DataGridViewElementStates.Visible; + StateInternal = State & ~DataGridViewElementStates.Visible; } OnStateChanged(DataGridViewElementStates.Visible); } } } - /// public virtual object Clone() { - DataGridViewBand dataGridViewBand = (DataGridViewBand) System.Activator.CreateInstance(this.GetType()); - if (dataGridViewBand != null) + DataGridViewBand band = (DataGridViewBand)Activator.CreateInstance(GetType()); + if (band != null) { - CloneInternal(dataGridViewBand); + CloneInternal(band); } - return dataGridViewBand; + return band; } internal void CloneInternal(DataGridViewBand dataGridViewBand) { - dataGridViewBand.propertyStore = new PropertyStore(); - dataGridViewBand.bandIndex = -1; - dataGridViewBand._bandIsRow = this._bandIsRow; - if (!this._bandIsRow || this.bandIndex >= 0 || this.DataGridView == null) + dataGridViewBand._propertyStore = new PropertyStore(); + dataGridViewBand._bandIndex = -1; + dataGridViewBand._bandIsRow = _bandIsRow; + if (!_bandIsRow || _bandIndex >= 0 || DataGridView == null) { - dataGridViewBand.StateInternal = this.State & ~(DataGridViewElementStates.Selected | DataGridViewElementStates.Displayed); + dataGridViewBand.StateInternal = State & ~(DataGridViewElementStates.Selected | DataGridViewElementStates.Displayed); } - dataGridViewBand.thickness = this.Thickness; - dataGridViewBand.MinimumThickness = this.MinimumThickness; - dataGridViewBand.cachedThickness = this.CachedThickness; - dataGridViewBand.DividerThickness = this.DividerThickness; - dataGridViewBand.Tag = this.Tag; - if (this.HasDefaultCellStyle) + dataGridViewBand._thickness = Thickness; + dataGridViewBand.MinimumThickness = MinimumThickness; + dataGridViewBand.CachedThickness = CachedThickness; + dataGridViewBand.DividerThickness = DividerThickness; + dataGridViewBand.Tag = Tag; + if (HasDefaultCellStyle) { - dataGridViewBand.DefaultCellStyle = new DataGridViewCellStyle(this.DefaultCellStyle); + dataGridViewBand.DefaultCellStyle = new DataGridViewCellStyle(DefaultCellStyle); } - if (this.HasDefaultHeaderCellType) + if (HasDefaultHeaderCellType) { - dataGridViewBand.DefaultHeaderCellType = this.DefaultHeaderCellType; + dataGridViewBand.DefaultHeaderCellType = DefaultHeaderCellType; } - if (this.ContextMenuStripInternal != null) + if (ContextMenuStripInternal != null) { - dataGridViewBand.ContextMenuStrip = this.ContextMenuStripInternal.Clone(); + dataGridViewBand.ContextMenuStrip = ContextMenuStripInternal.Clone(); } } private void DetachContextMenuStrip(object sender, EventArgs e) { - this.ContextMenuStripInternal = null; + ContextMenuStripInternal = null; } - - /// + public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } - /// protected virtual void Dispose(bool disposing) { - if (disposing) + if (disposing) { - ContextMenuStrip contextMenuStrip = (ContextMenuStrip)this.ContextMenuStripInternal; + ContextMenuStrip contextMenuStrip = (ContextMenuStrip)ContextMenuStripInternal; if (contextMenuStrip != null) { contextMenuStrip.Disposed -= new EventHandler(DetachContextMenuStrip); @@ -952,105 +828,100 @@ protected virtual void Dispose(bool disposing) internal void GetHeightInfo(int rowIndex, out int height, out int minimumHeight) { - Debug.Assert(this._bandIsRow); - if (this.DataGridView != null && - (this.DataGridView.VirtualMode || this.DataGridView.DataSource != null) && - this.DataGridView.AutoSizeRowsMode == DataGridViewAutoSizeRowsMode.None) + Debug.Assert(_bandIsRow); + if (DataGridView != null && + (DataGridView.VirtualMode || DataGridView.DataSource != null) && + DataGridView.AutoSizeRowsMode == DataGridViewAutoSizeRowsMode.None) { Debug.Assert(rowIndex > -1); - DataGridViewRowHeightInfoNeededEventArgs dgvrhine = this.DataGridView.OnRowHeightInfoNeeded(rowIndex, this.thickness, this.minimumThickness); - height = dgvrhine.Height; - minimumHeight = dgvrhine.MinimumHeight; + DataGridViewRowHeightInfoNeededEventArgs e = DataGridView.OnRowHeightInfoNeeded(rowIndex, _thickness, _minimumThickness); + height = e.Height; + minimumHeight = e.MinimumHeight; return; } - height = this.thickness; - minimumHeight = this.minimumThickness; + + height = _thickness; + minimumHeight = _minimumThickness; } internal void OnStateChanged(DataGridViewElementStates elementState) { - if (this.DataGridView != null) + if (DataGridView != null) { // maybe move this code into OnDataGridViewElementStateChanged - if (this._bandIsRow) + if (_bandIsRow) { // we could be smarter about what needs to be invalidated. - this.DataGridView.Rows.InvalidateCachedRowCount(elementState); - this.DataGridView.Rows.InvalidateCachedRowsHeight(elementState); - if (this.bandIndex != -1) + DataGridView.Rows.InvalidateCachedRowCount(elementState); + DataGridView.Rows.InvalidateCachedRowsHeight(elementState); + if (_bandIndex != -1) { - this.DataGridView.OnDataGridViewElementStateChanged(this, -1, elementState); + DataGridView.OnDataGridViewElementStateChanged(this, -1, elementState); } } else { // we could be smarter about what needs to be invalidated. - this.DataGridView.Columns.InvalidateCachedColumnCount(elementState); - this.DataGridView.Columns.InvalidateCachedColumnsWidth(elementState); - this.DataGridView.OnDataGridViewElementStateChanged(this, -1, elementState); + DataGridView.Columns.InvalidateCachedColumnCount(elementState); + DataGridView.Columns.InvalidateCachedColumnsWidth(elementState); + DataGridView.OnDataGridViewElementStateChanged(this, -1, elementState); } } } - private void OnStateChanging(DataGridViewElementStates elementState) + private void OnStateChanging(DataGridViewElementStates elementState) { - if (this.DataGridView != null) + if (DataGridView != null) { - if (this._bandIsRow) + if (_bandIsRow) { - if (this.bandIndex != -1) + if (_bandIndex != -1) { - this.DataGridView.OnDataGridViewElementStateChanging(this, -1, elementState); + DataGridView.OnDataGridViewElementStateChanging(this, -1, elementState); } } else { - this.DataGridView.OnDataGridViewElementStateChanging(this, -1, elementState); + DataGridView.OnDataGridViewElementStateChanging(this, -1, elementState); } } } - /// protected override void OnDataGridViewChanged() { - if (this.HasDefaultCellStyle) + if (HasDefaultCellStyle) { - if (this.DataGridView == null) + if (DataGridView == null) { - this.DefaultCellStyle.RemoveScope(this._bandIsRow ? DataGridViewCellStyleScopes.Row : DataGridViewCellStyleScopes.Column); + DefaultCellStyle.RemoveScope(_bandIsRow ? DataGridViewCellStyleScopes.Row : DataGridViewCellStyleScopes.Column); } else { - this.DefaultCellStyle.AddScope(this.DataGridView, - this._bandIsRow ? DataGridViewCellStyleScopes.Row : DataGridViewCellStyleScopes.Column); + DefaultCellStyle.AddScope(DataGridView, _bandIsRow ? DataGridViewCellStyleScopes.Row : DataGridViewCellStyleScopes.Column); } } + base.OnDataGridViewChanged(); } - private bool ShouldSerializeDefaultHeaderCellType() + private bool ShouldSerializeDefaultHeaderCellType() { - Type dhct = (Type)this.Properties.GetObject(PropDefaultHeaderCellType); - return dhct != null; + return Properties.GetObject(s_propDefaultHeaderCellType) != null; } // internal because DataGridViewColumn needs to access it internal bool ShouldSerializeResizable() { - return (this.State & DataGridViewElementStates.ResizableSet) != 0; + return (State & DataGridViewElementStates.ResizableSet) != 0; } - /// - /// - /// - /// public override string ToString() { - StringBuilder sb = new StringBuilder(36); - sb.Append("DataGridViewBand { Index="); - sb.Append(this.Index.ToString(CultureInfo.CurrentCulture)); - sb.Append(" }"); - return sb.ToString(); + var builder = new StringBuilder(36); + builder.Append("DataGridViewBand { Index="); + builder.Append(Index); + builder.Append(" }"); + return builder.ToString(); } } } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCell.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCell.cs index 0f63350ecba..21c65237330 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCell.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCell.cs @@ -1960,7 +1960,7 @@ static internal DataGridViewFreeDimension GetFreeDimensionFromConstraint(Size co { if (constraintSize.Width < 0 || constraintSize.Height < 0) { - throw new ArgumentException(string.Format(SR.InvalidArgument, "constraintSize", constraintSize.ToString())); + throw new ArgumentException(string.Format(SR.InvalidArgument, nameof(constraintSize), constraintSize)); } if (constraintSize.Width == 0) { @@ -1981,7 +1981,7 @@ static internal DataGridViewFreeDimension GetFreeDimensionFromConstraint(Size co } else { - throw new ArgumentException(string.Format(SR.InvalidArgument, "constraintSize", constraintSize.ToString())); + throw new ArgumentException(string.Format(SR.InvalidArgument, nameof(constraintSize), constraintSize)); } } } @@ -2056,7 +2056,7 @@ public virtual DataGridViewElementStates GetInheritedState(int rowIndex) Debug.Assert(this.RowIndex == -1); if (rowIndex != -1) { - throw new ArgumentException(string.Format(SR.InvalidArgument, "rowIndex", rowIndex.ToString(CultureInfo.CurrentCulture))); + throw new ArgumentException(string.Format(SR.InvalidArgument, nameof(rowIndex), rowIndex)); } if (this.owningRow != null) { @@ -2081,7 +2081,7 @@ public virtual DataGridViewElementStates GetInheritedState(int rowIndex) if (this.DataGridView.Rows.SharedRow(rowIndex) != this.owningRow) { - throw new ArgumentException(string.Format(SR.InvalidArgument, "rowIndex", rowIndex.ToString(CultureInfo.CurrentCulture))); + throw new ArgumentException(string.Format(SR.InvalidArgument, nameof(rowIndex), rowIndex)); } DataGridViewElementStates rowEffectiveState = this.DataGridView.Rows.GetRowState(rowIndex); @@ -2841,7 +2841,7 @@ public static int MeasureTextHeight(Graphics graphics, string text, Font font, i if (maxWidth <= 0) { - throw new ArgumentOutOfRangeException(nameof(maxWidth), string.Format(SR.InvalidLowBoundArgument, "maxWidth", (maxWidth).ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(maxWidth), string.Format(SR.InvalidLowBoundArgument, "maxWidth", (maxWidth).ToString(CultureInfo.CurrentCulture), 0)); } if (!DataGridViewUtilities.ValidTextFormatFlags(flags)) @@ -2945,7 +2945,7 @@ public static int MeasureTextWidth(Graphics graphics, string text, Font font, in { if (maxHeight <= 0) { - throw new ArgumentOutOfRangeException(nameof(maxHeight), string.Format(SR.InvalidLowBoundArgument, "maxHeight", (maxHeight).ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(maxHeight), string.Format(SR.InvalidLowBoundArgument, "maxHeight", (maxHeight).ToString(CultureInfo.CurrentCulture), 0)); } Size oneLineSize = DataGridViewCell.MeasureTextSize(graphics, text, font, flags); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumn.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumn.cs index c77ecd5a04d..af984d71583 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumn.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumn.cs @@ -365,18 +365,19 @@ public int DisplayIndex { if (value == int.MaxValue) { - throw new ArgumentOutOfRangeException(nameof(DisplayIndex), value, string.Format(SR.DataGridViewColumn_DisplayIndexTooLarge, int.MaxValue.ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.DataGridViewColumn_DisplayIndexTooLarge, int.MaxValue)); } - if (this.DataGridView != null) + if (DataGridView != null) { if (value < 0) { - throw new ArgumentOutOfRangeException(nameof(DisplayIndex), value, string.Format(SR.DataGridViewColumn_DisplayIndexNegative)); + throw new ArgumentOutOfRangeException(nameof(value), value, SR.DataGridViewColumn_DisplayIndexNegative); } if (value >= this.DataGridView.Columns.Count) { - throw new ArgumentOutOfRangeException(nameof(DisplayIndex), value, string.Format(SR.DataGridViewColumn_DisplayIndexExceedsColumnCount)); + throw new ArgumentOutOfRangeException(nameof(value), value, SR.DataGridViewColumn_DisplayIndexExceedsColumnCount); } + // Will throw an error if a visible frozen column is placed inside a non-frozen area or vice-versa. this.DataGridView.OnColumnDisplayIndexChanging(this, value); this.displayIndex = value; @@ -485,11 +486,11 @@ public float FillWeight { if (value <= 0) { - throw new ArgumentOutOfRangeException(nameof(FillWeight), string.Format(SR.InvalidLowBoundArgument, "FillWeight", (value).ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgument, nameof(FillWeight), value, 0)); } if (value > (float)ushort.MaxValue) { - throw new ArgumentOutOfRangeException(nameof(FillWeight), string.Format(SR.InvalidHighBoundArgumentEx, "FillWeight", (value).ToString(CultureInfo.CurrentCulture), (ushort.MaxValue).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidHighBoundArgumentEx, nameof(FillWeight), value, ushort.MaxValue)); } if (this.DataGridView != null) { diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnCollection.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnCollection.cs index e36bf6226c2..15b2c995093 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnCollection.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnCollection.cs @@ -524,7 +524,7 @@ public int GetColumnCount(DataGridViewElementStates includeFilter) if ((includeFilter & ~(DataGridViewElementStates.Displayed | DataGridViewElementStates.Frozen | DataGridViewElementStates.Resizable | DataGridViewElementStates.ReadOnly | DataGridViewElementStates.Selected | DataGridViewElementStates.Visible)) != 0) { - throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, "includeFilter")); + throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, nameof(includeFilter))); } // cache returned value and reuse it as long as none @@ -655,7 +655,7 @@ public int GetColumnsWidth(DataGridViewElementStates includeFilter) if ((includeFilter & ~(DataGridViewElementStates.Displayed | DataGridViewElementStates.Frozen | DataGridViewElementStates.Resizable | DataGridViewElementStates.ReadOnly | DataGridViewElementStates.Selected | DataGridViewElementStates.Visible)) != 0) { - throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, "includeFilter")); + throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, nameof(includeFilter))); } // cache returned value and reuse it as long as none @@ -703,7 +703,7 @@ public DataGridViewColumn GetFirstColumn(DataGridViewElementStates includeFilter if ((includeFilter & ~(DataGridViewElementStates.Displayed | DataGridViewElementStates.Frozen | DataGridViewElementStates.Resizable | DataGridViewElementStates.ReadOnly | DataGridViewElementStates.Selected | DataGridViewElementStates.Visible)) != 0) { - throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, "includeFilter")); + throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, nameof(includeFilter))); } if (this.itemsSorted == null) @@ -738,12 +738,12 @@ public DataGridViewColumn GetFirstColumn(DataGridViewElementStates includeFilter if ((includeFilter & ~(DataGridViewElementStates.Displayed | DataGridViewElementStates.Frozen | DataGridViewElementStates.Resizable | DataGridViewElementStates.ReadOnly | DataGridViewElementStates.Selected | DataGridViewElementStates.Visible)) != 0) { - throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, "includeFilter")); + throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, nameof(includeFilter))); } if ((excludeFilter & ~(DataGridViewElementStates.Displayed | DataGridViewElementStates.Frozen | DataGridViewElementStates.Resizable | DataGridViewElementStates.ReadOnly | DataGridViewElementStates.Selected | DataGridViewElementStates.Visible)) != 0) { - throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, "excludeFilter")); + throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, nameof(excludeFilter))); } if (this.itemsSorted == null) @@ -775,12 +775,12 @@ public DataGridViewColumn GetLastColumn(DataGridViewElementStates includeFilter, if ((includeFilter & ~(DataGridViewElementStates.Displayed | DataGridViewElementStates.Frozen | DataGridViewElementStates.Resizable | DataGridViewElementStates.ReadOnly | DataGridViewElementStates.Selected | DataGridViewElementStates.Visible)) != 0) { - throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, "includeFilter")); + throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, nameof(includeFilter))); } if ((excludeFilter & ~(DataGridViewElementStates.Displayed | DataGridViewElementStates.Frozen | DataGridViewElementStates.Resizable | DataGridViewElementStates.ReadOnly | DataGridViewElementStates.Selected | DataGridViewElementStates.Visible)) != 0) { - throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, "excludeFilter")); + throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, nameof(excludeFilter))); } if (this.itemsSorted == null) @@ -817,12 +817,12 @@ public DataGridViewColumn GetNextColumn(DataGridViewColumn dataGridViewColumnSta if ((includeFilter & ~(DataGridViewElementStates.Displayed | DataGridViewElementStates.Frozen | DataGridViewElementStates.Resizable | DataGridViewElementStates.ReadOnly | DataGridViewElementStates.Selected | DataGridViewElementStates.Visible)) != 0) { - throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, "includeFilter")); + throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, nameof(includeFilter))); } if ((excludeFilter & ~(DataGridViewElementStates.Displayed | DataGridViewElementStates.Frozen | DataGridViewElementStates.Resizable | DataGridViewElementStates.ReadOnly | DataGridViewElementStates.Selected | DataGridViewElementStates.Visible)) != 0) { - throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, "excludeFilter")); + throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, nameof(excludeFilter))); } if (this.itemsSorted == null) @@ -889,12 +889,12 @@ public DataGridViewColumn GetPreviousColumn(DataGridViewColumn dataGridViewColum if ((includeFilter & ~(DataGridViewElementStates.Displayed | DataGridViewElementStates.Frozen | DataGridViewElementStates.Resizable | DataGridViewElementStates.ReadOnly | DataGridViewElementStates.Selected | DataGridViewElementStates.Visible)) != 0) { - throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, "includeFilter")); + throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, nameof(includeFilter))); } if ((excludeFilter & ~(DataGridViewElementStates.Displayed | DataGridViewElementStates.Frozen | DataGridViewElementStates.Resizable | DataGridViewElementStates.ReadOnly | DataGridViewElementStates.Selected | DataGridViewElementStates.Visible)) != 0) { - throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, "excludeFilter")); + throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, nameof(excludeFilter))); } if (this.itemsSorted == null) @@ -1154,18 +1154,18 @@ public virtual void RemoveAt(int index) { if (index < 0 || index >= this.Count) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } if (this.DataGridView.NoDimensionChangeAllowed) { - throw new InvalidOperationException(string.Format(SR.DataGridView_ForbiddenOperationInEventHandler)); + throw new InvalidOperationException(SR.DataGridView_ForbiddenOperationInEventHandler); } if (this.DataGridView.InDisplayIndexAdjustments) { // We are within columns display indexes adjustments. We do not allow changing the column collection while adjusting display indexes. - throw new InvalidOperationException(string.Format(SR.DataGridView_CannotAlterDisplayIndexWithinAdjustments)); + throw new InvalidOperationException(SR.DataGridView_CannotAlterDisplayIndexWithinAdjustments); } RemoveAtInternal(index, false /*force*/); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxCell.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxCell.cs index bca796f8908..c5cda2b6d8e 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxCell.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxCell.cs @@ -445,7 +445,7 @@ public virtual int DropDownWidth //CheckNoSharedCell(); if (value < 1) { - throw new ArgumentOutOfRangeException(nameof(DropDownWidth), value, string.Format(SR.DataGridViewComboBoxCell_DropDownWidthOutOfRange, (1).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(DropDownWidth), value, string.Format(SR.DataGridViewComboBoxCell_DropDownWidthOutOfRange, 1)); } this.Properties.SetInteger(PropComboBoxCellDropDownWidth, (int)value); if (OwnsEditingComboBox(this.RowIndex)) @@ -566,7 +566,7 @@ public virtual int MaxDropDownItems //CheckNoSharedCell(); if (value < 1 || value > 100) { - throw new ArgumentOutOfRangeException(nameof(MaxDropDownItems), value, string.Format(SR.DataGridViewComboBoxCell_MaxDropDownItemsOutOfRange, (1).ToString(CultureInfo.CurrentCulture), (100).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(MaxDropDownItems), value, string.Format(SR.DataGridViewComboBoxCell_MaxDropDownItemsOutOfRange, 1, 100)); } this.Properties.SetInteger(PropComboBoxCellMaxDropDownItems, (int)value); if (OwnsEditingComboBox(this.RowIndex)) @@ -2941,7 +2941,7 @@ public virtual object this[int index] { if (index < 0 || index >= this.InnerArray.Count) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } return this.InnerArray[index]; } @@ -2957,7 +2957,7 @@ public virtual object this[int index] if (index < 0 || index >= this.InnerArray.Count) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } this.InnerArray[index] = value; @@ -3054,7 +3054,7 @@ public void Insert(int index, object item) if (index < 0 || index > this.InnerArray.Count) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), nameof(index))); } // If the combo box is sorted, then just treat this like an add @@ -3096,7 +3096,7 @@ public void RemoveAt(int index) if (index < 0 || index >= this.InnerArray.Count) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } this.InnerArray.RemoveAt(index); this.owner.OnItemsCollectionChanged(); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewHeaderCell.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewHeaderCell.cs index 5c3bf329d05..d5e3aff993d 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewHeaderCell.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewHeaderCell.cs @@ -331,11 +331,11 @@ public override DataGridViewElementStates GetInheritedState(int rowIndex) if ((this.DataGridView == null && rowIndex != -1) || (this.DataGridView != null && (rowIndex < 0 || rowIndex >= this.DataGridView.Rows.Count))) { - throw new ArgumentException(string.Format(SR.InvalidArgument, "rowIndex", rowIndex.ToString(CultureInfo.CurrentCulture))); + throw new ArgumentException(string.Format(SR.InvalidArgument, nameof(rowIndex), rowIndex)); } if (this.DataGridView != null && this.DataGridView.Rows.SharedRow(rowIndex) != this.OwningRow) { - throw new ArgumentException(string.Format(SR.InvalidArgument, "rowIndex", rowIndex.ToString(CultureInfo.CurrentCulture))); + throw new ArgumentException(string.Format(SR.InvalidArgument, nameof(rowIndex), rowIndex)); } state |= (this.OwningRow.GetState(rowIndex) & DataGridViewElementStates.Frozen); if (this.OwningRow.GetResizable(rowIndex) == DataGridViewTriState.True || (this.DataGridView != null && this.DataGridView.RowHeadersWidthSizeMode == DataGridViewRowHeadersWidthSizeMode.EnableResizing)) @@ -460,7 +460,7 @@ protected override Size GetSize(int rowIndex) } if (this.DataGridView.Rows.SharedRow(rowIndex) != this.OwningRow) { - throw new ArgumentException(string.Format(SR.InvalidArgument, "rowIndex", rowIndex.ToString(CultureInfo.CurrentCulture))); + throw new ArgumentException(string.Format(SR.InvalidArgument, nameof(rowIndex), rowIndex)); } return new Size(this.DataGridView.RowHeadersWidth, this.OwningRow.GetHeight(rowIndex)); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewMethods.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewMethods.cs index a3aea550e95..ee0f26bcf9a 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewMethods.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewMethods.cs @@ -325,9 +325,9 @@ private bool AdjustExpandingColumn(DataGridViewColumn dataGridViewColumn, int ro this.noAutoSizeCount++; DataGridViewRow dataGridViewRow = this.Rows.SharedRow(rowIndex); int preferredThickness = dataGridViewRow.Cells[dataGridViewColumn.Index].GetPreferredWidth(rowIndex, dataGridViewRow.GetHeight(rowIndex)); - if (preferredThickness > DataGridViewBand.maxBandThickness) + if (preferredThickness > DataGridViewBand.MaxBandThickness) { - preferredThickness = DataGridViewBand.maxBandThickness; + preferredThickness = DataGridViewBand.MaxBandThickness; } if (dataGridViewColumn.Width < preferredThickness) { @@ -415,9 +415,9 @@ private int AdjustExpandingRow(int rowIndex, int columnIndex, bool fixedWidth) preferredThickness = height; } Debug.Assert(preferredThickness >= minimumHeight); - if (preferredThickness > DataGridViewBand.maxBandThickness) + if (preferredThickness > DataGridViewBand.MaxBandThickness) { - preferredThickness = DataGridViewBand.maxBandThickness; + preferredThickness = DataGridViewBand.MaxBandThickness; } if (height != preferredThickness) { @@ -1883,9 +1883,9 @@ private bool AutoResizeColumnInternal(int columnIndex, DataGridViewAutoSizeColum { preferredColumnWidth = dataGridViewColumn.MinimumThickness; } - if (preferredColumnWidth > DataGridViewBand.maxBandThickness) + if (preferredColumnWidth > DataGridViewBand.MaxBandThickness) { - preferredColumnWidth = DataGridViewBand.maxBandThickness; + preferredColumnWidth = DataGridViewBand.MaxBandThickness; } if (preferredColumnWidth != dataGridViewColumn.Thickness) { @@ -2315,9 +2315,9 @@ private void AutoResizeRowInternal(int rowIndex, DataGridViewAutoSizeRowMode aut { preferredThickness = minimumHeight; } - if (preferredThickness > DataGridViewBand.maxBandThickness) + if (preferredThickness > DataGridViewBand.MaxBandThickness) { - preferredThickness = DataGridViewBand.maxBandThickness; + preferredThickness = DataGridViewBand.MaxBandThickness; } if (height != preferredThickness) { @@ -2561,7 +2561,7 @@ private Rectangle GetResizeClipRectangle(int columnIndex) { clip.X = this.layout.Data.X - this.mouseBarOffset - 1; clip.Width = leftEdge - this.Columns[columnIndex].MinimumThickness - this.layout.Data.X + 3; - int overflowWidth = leftEdge - this.mouseBarOffset - clip.Left - DataGridViewBand.maxBandThickness + 1; + int overflowWidth = leftEdge - this.mouseBarOffset - clip.Left - DataGridViewBand.MaxBandThickness + 1; if (overflowWidth > 0) { clip.X += overflowWidth; @@ -2572,7 +2572,7 @@ private Rectangle GetResizeClipRectangle(int columnIndex) { clip.X = leftEdge + this.Columns[columnIndex].MinimumThickness - this.mouseBarOffset - 1; clip.Width = this.layout.Data.Right - leftEdge - 1; - int overflowWidth = clip.Right + this.mouseBarOffset - leftEdge - DataGridViewBand.maxBandThickness; + int overflowWidth = clip.Right + this.mouseBarOffset - leftEdge - DataGridViewBand.MaxBandThickness; if (overflowWidth > 0) { clip.Width -= overflowWidth; @@ -6139,7 +6139,7 @@ private void EndColumnResize(int x) { int proposed = this.Columns[this.trackColumn].Thickness + delta; Debug.Assert(proposed >= this.Columns[this.trackColumn].MinimumThickness); - Debug.Assert(proposed <= DataGridViewBand.maxBandThickness); + Debug.Assert(proposed <= DataGridViewBand.MaxBandThickness); this.Columns[this.trackColumn].Thickness = proposed; } } @@ -6424,7 +6424,7 @@ private void FlushDisplayedChanged() else { Rectangle rectScreen = Screen.FromControl(this).WorkingArea; - int maxDisplayedRows = (int) (rectScreen.Height / DataGridViewBand.minBandThickness); + int maxDisplayedRows = (int) (rectScreen.Height / DataGridViewBand.MinBandThickness); // Make sure all displayed scrolling rows have the Displayed state. int rowIndexTmp = this.displayedBandsInfo.FirstDisplayedScrollingRow; @@ -6891,7 +6891,7 @@ public int GetCellCount(DataGridViewElementStates includeFilter) if ((includeFilter & ~(DataGridViewElementStates.Displayed | DataGridViewElementStates.Frozen | DataGridViewElementStates.Resizable | DataGridViewElementStates.ReadOnly | DataGridViewElementStates.Selected | DataGridViewElementStates.Visible)) != 0) { - throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, "includeFilter")); + throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, nameof(includeFilter))); } int cellCount = 0; @@ -10908,7 +10908,7 @@ internal void OnAddingColumn(DataGridViewColumn dataGridViewColumn) float weightSum = this.Columns.GetColumnsFillWeight(DataGridViewElementStates.None) + dataGridViewColumn.FillWeight; if (weightSum > (float)ushort.MaxValue) { - throw new InvalidOperationException(string.Format(SR.DataGridView_WeightSumCannotExceedLongMaxValue, (ushort.MaxValue).ToString(CultureInfo.CurrentCulture))); + throw new InvalidOperationException(string.Format(SR.DataGridView_WeightSumCannotExceedLongMaxValue, ushort.MaxValue)); } // check for correctness of frozen state - throws exception if state is incorrect. @@ -11030,7 +11030,7 @@ internal void OnAddingColumns(DataGridViewColumn[] dataGridViewColumns) weightSum += dataGridViewColumn.FillWeight; if (weightSum > (float)ushort.MaxValue) { - throw new InvalidOperationException(string.Format(SR.DataGridView_WeightSumCannotExceedLongMaxValue, (ushort.MaxValue).ToString(CultureInfo.CurrentCulture))); + throw new InvalidOperationException(string.Format(SR.DataGridView_WeightSumCannotExceedLongMaxValue, ushort.MaxValue)); } } @@ -13968,7 +13968,7 @@ internal void OnColumnFillWeightChanging(DataGridViewColumn dataGridViewColumn, float weightSum = this.Columns.GetColumnsFillWeight(DataGridViewElementStates.None) - dataGridViewColumn.FillWeight + fillWeight; if (weightSum > (float)ushort.MaxValue) { - throw new InvalidOperationException(string.Format(SR.DataGridView_WeightSumCannotExceedLongMaxValue, (ushort.MaxValue).ToString(CultureInfo.CurrentCulture))); + throw new InvalidOperationException(string.Format(SR.DataGridView_WeightSumCannotExceedLongMaxValue, ushort.MaxValue)); } } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRow.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRow.cs index dcc1ca2f132..d0fab9403db 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRow.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRow.cs @@ -1355,7 +1355,7 @@ public virtual DataGridViewElementStates GetState(int rowIndex) { if (rowIndex != Index) { - throw new ArgumentException(string.Format(SR.InvalidArgument, nameof(rowIndex), rowIndex.ToString(CultureInfo.CurrentCulture))); + throw new ArgumentException(string.Format(SR.InvalidArgument, nameof(rowIndex), rowIndex), nameof(rowIndex)); } return base.State; } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowCollection.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowCollection.cs index e3638e699c9..9b58c7c73d3 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowCollection.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowCollection.cs @@ -1025,7 +1025,7 @@ public int GetFirstRow(DataGridViewElementStates includeFilter) if ((includeFilter & ~(DataGridViewElementStates.Displayed | DataGridViewElementStates.Frozen | DataGridViewElementStates.Resizable | DataGridViewElementStates.ReadOnly | DataGridViewElementStates.Selected | DataGridViewElementStates.Visible)) != 0) { - throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, "includeFilter")); + throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, nameof(includeFilter))); } #if DEBUG Debug.Assert(this.cachedRowCountsAccessAllowed); @@ -1071,12 +1071,12 @@ public int GetFirstRow(DataGridViewElementStates includeFilter, if ((includeFilter & ~(DataGridViewElementStates.Displayed | DataGridViewElementStates.Frozen | DataGridViewElementStates.Resizable | DataGridViewElementStates.ReadOnly | DataGridViewElementStates.Selected | DataGridViewElementStates.Visible)) != 0) { - throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, "includeFilter")); + throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, nameof(includeFilter))); } if ((excludeFilter & ~(DataGridViewElementStates.Displayed | DataGridViewElementStates.Frozen | DataGridViewElementStates.Resizable | DataGridViewElementStates.ReadOnly | DataGridViewElementStates.Selected | DataGridViewElementStates.Visible)) != 0) { - throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, "excludeFilter")); + throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, nameof(excludeFilter))); } #if DEBUG Debug.Assert(this.cachedRowCountsAccessAllowed); @@ -1117,7 +1117,7 @@ public int GetLastRow(DataGridViewElementStates includeFilter) if ((includeFilter & ~(DataGridViewElementStates.Displayed | DataGridViewElementStates.Frozen | DataGridViewElementStates.Resizable | DataGridViewElementStates.ReadOnly | DataGridViewElementStates.Selected | DataGridViewElementStates.Visible)) != 0) { - throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, "includeFilter")); + throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, nameof(includeFilter))); } #if DEBUG Debug.Assert(this.cachedRowCountsAccessAllowed); @@ -1173,11 +1173,11 @@ public int GetNextRow(int indexStart, DataGridViewElementStates includeFilter) if ((includeFilter & ~(DataGridViewElementStates.Displayed | DataGridViewElementStates.Frozen | DataGridViewElementStates.Resizable | DataGridViewElementStates.ReadOnly | DataGridViewElementStates.Selected | DataGridViewElementStates.Visible)) != 0) { - throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, "includeFilter")); + throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, nameof(includeFilter))); } if (indexStart < -1) { - throw new ArgumentOutOfRangeException(nameof(indexStart), string.Format(SR.InvalidLowBoundArgumentEx, "indexStart", (indexStart).ToString(CultureInfo.CurrentCulture), (-1).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(indexStart), indexStart, string.Format(SR.InvalidLowBoundArgumentEx, nameof(indexStart), indexStart, -1)); } int index = indexStart + 1; @@ -1200,16 +1200,16 @@ public int GetNextRow(int indexStart, if ((includeFilter & ~(DataGridViewElementStates.Displayed | DataGridViewElementStates.Frozen | DataGridViewElementStates.Resizable | DataGridViewElementStates.ReadOnly | DataGridViewElementStates.Selected | DataGridViewElementStates.Visible)) != 0) { - throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, "includeFilter")); + throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, nameof(includeFilter))); } if ((excludeFilter & ~(DataGridViewElementStates.Displayed | DataGridViewElementStates.Frozen | DataGridViewElementStates.Resizable | DataGridViewElementStates.ReadOnly | DataGridViewElementStates.Selected | DataGridViewElementStates.Visible)) != 0) { - throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, "excludeFilter")); + throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, nameof(excludeFilter))); } if (indexStart < -1) { - throw new ArgumentOutOfRangeException(nameof(indexStart), string.Format(SR.InvalidLowBoundArgumentEx, "indexStart", (indexStart).ToString(CultureInfo.CurrentCulture), (-1).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(indexStart), indexStart, string.Format(SR.InvalidLowBoundArgumentEx, nameof(indexStart), indexStart, -1)); } int index = indexStart + 1; @@ -1226,11 +1226,11 @@ public int GetPreviousRow(int indexStart, DataGridViewElementStates includeFilte if ((includeFilter & ~(DataGridViewElementStates.Displayed | DataGridViewElementStates.Frozen | DataGridViewElementStates.Resizable | DataGridViewElementStates.ReadOnly | DataGridViewElementStates.Selected | DataGridViewElementStates.Visible)) != 0) { - throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, "includeFilter")); + throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, nameof(includeFilter))); } if (indexStart > this.items.Count) { - throw new ArgumentOutOfRangeException(nameof(indexStart), string.Format(SR.InvalidHighBoundArgumentEx, "indexStart", (indexStart).ToString(CultureInfo.CurrentCulture), (this.items.Count).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(indexStart), indexStart, string.Format(SR.InvalidHighBoundArgumentEx, nameof(indexStart), indexStart, items.Count)); } int index = indexStart - 1; @@ -1253,16 +1253,16 @@ public int GetPreviousRow(int indexStart, if ((includeFilter & ~(DataGridViewElementStates.Displayed | DataGridViewElementStates.Frozen | DataGridViewElementStates.Resizable | DataGridViewElementStates.ReadOnly | DataGridViewElementStates.Selected | DataGridViewElementStates.Visible)) != 0) { - throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, "includeFilter")); + throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, nameof(includeFilter))); } if ((excludeFilter & ~(DataGridViewElementStates.Displayed | DataGridViewElementStates.Frozen | DataGridViewElementStates.Resizable | DataGridViewElementStates.ReadOnly | DataGridViewElementStates.Selected | DataGridViewElementStates.Visible)) != 0) { - throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, "excludeFilter")); + throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, nameof(excludeFilter))); } if (indexStart > this.items.Count) { - throw new ArgumentOutOfRangeException(nameof(indexStart), string.Format(SR.InvalidHighBoundArgumentEx, "indexStart", (indexStart).ToString(CultureInfo.CurrentCulture), (this.items.Count).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(indexStart), indexStart, string.Format(SR.InvalidHighBoundArgumentEx, nameof(indexStart), indexStart, items.Count)); } int index = indexStart - 1; @@ -1279,7 +1279,7 @@ public int GetRowCount(DataGridViewElementStates includeFilter) if ((includeFilter & ~(DataGridViewElementStates.Displayed | DataGridViewElementStates.Frozen | DataGridViewElementStates.Resizable | DataGridViewElementStates.ReadOnly | DataGridViewElementStates.Selected | DataGridViewElementStates.Visible)) != 0) { - throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, "includeFilter")); + throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, nameof(includeFilter))); } #if DEBUG Debug.Assert(this.cachedRowCountsAccessAllowed); @@ -1355,7 +1355,7 @@ public int GetRowsHeight(DataGridViewElementStates includeFilter) if ((includeFilter & ~(DataGridViewElementStates.Displayed | DataGridViewElementStates.Frozen | DataGridViewElementStates.Resizable | DataGridViewElementStates.ReadOnly | DataGridViewElementStates.Selected | DataGridViewElementStates.Visible)) != 0) { - throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, "includeFilter")); + throw new ArgumentException(string.Format(SR.DataGridView_InvalidDataGridViewElementStateCombination, nameof(includeFilter))); } #if DEBUG Debug.Assert(this.cachedRowHeightsAccessAllowed); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowHeightInfoNeededEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowHeightInfoNeededEventArgs.cs index c11476d85aa..6b735e6407d 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowHeightInfoNeededEventArgs.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowHeightInfoNeededEventArgs.cs @@ -30,9 +30,9 @@ public int Height { value = _minimumHeight; } - if (value > DataGridViewBand.maxBandThickness) + if (value > DataGridViewBand.MaxBandThickness) { - throw new ArgumentOutOfRangeException(nameof(Height), string.Format(SR.InvalidHighBoundArgumentEx, "Height", (value).ToString(CultureInfo.CurrentCulture), (DataGridViewBand.maxBandThickness).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), string.Format(SR.InvalidHighBoundArgumentEx, nameof(Height), value, DataGridViewBand.MaxBandThickness)); } _height = value; @@ -44,9 +44,9 @@ public int MinimumHeight get => _minimumHeight; set { - if (value < DataGridViewBand.minBandThickness) + if (value < DataGridViewBand.MinBandThickness) { - throw new ArgumentOutOfRangeException(nameof(MinimumHeight), value, string.Format(SR.DataGridViewBand_MinimumHeightSmallerThanOne, (DataGridViewBand.minBandThickness).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.DataGridViewBand_MinimumHeightSmallerThanOne, DataGridViewBand.MinBandThickness)); } if (_height < value) diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowsRemovedEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowsRemovedEventArgs.cs index a1bcb56c17d..a0f3c78d38a 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowsRemovedEventArgs.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowsRemovedEventArgs.cs @@ -12,11 +12,11 @@ public DataGridViewRowsRemovedEventArgs(int rowIndex, int rowCount) { if (rowIndex < 0) { - throw new ArgumentOutOfRangeException(nameof(rowIndex), string.Format(SR.InvalidLowBoundArgumentEx, nameof(rowIndex), rowIndex.ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(rowIndex), string.Format(SR.InvalidLowBoundArgumentEx, nameof(rowIndex), rowIndex.ToString(CultureInfo.CurrentCulture), 0)); } if (rowCount < 1) { - throw new ArgumentOutOfRangeException(nameof(rowCount), string.Format(SR.InvalidLowBoundArgumentEx, nameof(rowCount), rowCount.ToString(CultureInfo.CurrentCulture), (1).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(rowCount), string.Format(SR.InvalidLowBoundArgumentEx, nameof(rowCount), rowCount.ToString(CultureInfo.CurrentCulture), 1)); } RowIndex = rowIndex; diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTextBoxCell.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTextBoxCell.cs index c3184f84409..0a553a0601c 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTextBoxCell.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTextBoxCell.cs @@ -105,14 +105,11 @@ public virtual int MaxInputLength } set { - //if (this.DataGridView != null && this.RowIndex == -1) - //{ - // throw new InvalidOperationException(string.Format(SR.DataGridView_InvalidOperationOnSharedCell)); - //} if (value < 0) { - throw new ArgumentOutOfRangeException(nameof(MaxInputLength), string.Format(SR.InvalidLowBoundArgumentEx, "MaxInputLength", value.ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), string.Format(SR.InvalidLowBoundArgumentEx, nameof(MaxInputLength), value, 0)); } + this.Properties.SetInteger(PropTextBoxCellMaxInputLength, value); if (OwnsEditingTextBox(this.RowIndex)) { diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DateTimePicker.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DateTimePicker.cs index 590dd2d258b..5ea5fdea3fe 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/DateTimePicker.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/DateTimePicker.cs @@ -703,12 +703,11 @@ public DateTime MaxDate { if (value != max) { if (value < EffectiveMinDate(min)) { - throw new ArgumentOutOfRangeException(nameof(MaxDate), string.Format(SR.InvalidLowBoundArgumentEx, "MaxDate", FormatDateTime(value), "MinDate")); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(MaxDate), FormatDateTime(value), nameof(MinDate))); } - - // If trying to set the maximum greater than MaxDateTime, throw. - if (value > MaximumDateTime) { - throw new ArgumentOutOfRangeException(nameof(MaxDate), string.Format(SR.DateTimePickerMaxDate, FormatDateTime(DateTimePicker.MaxDateTime))); + if (value > MaximumDateTime) + { + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.DateTimePickerMaxDate, FormatDateTime(DateTimePicker.MaxDateTime))); } max = value; @@ -757,13 +756,11 @@ public DateTime MinDate { { if (value > EffectiveMaxDate(max)) { - throw new ArgumentOutOfRangeException(nameof(MinDate), string.Format(SR.InvalidHighBoundArgument, "MinDate", FormatDateTime(value), "MaxDate")); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidHighBoundArgument, nameof(MinDate), FormatDateTime(value), nameof(MaxDate))); } - - // If trying to set the minimum less than MinimumDateTime, throw. if (value < MinimumDateTime) { - throw new ArgumentOutOfRangeException(nameof(MinDate), string.Format(SR.DateTimePickerMinDate, FormatDateTime(DateTimePicker.MinimumDateTime))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.DateTimePickerMinDate, FormatDateTime(DateTimePicker.MinimumDateTime))); } min = value; @@ -993,7 +990,7 @@ public DateTime Value { // update anyway. if (!userHasSetValue || valueChanged) { if ((value < MinDate) || (value > MaxDate)) { - throw new ArgumentOutOfRangeException(nameof(Value), string.Format(SR.InvalidBoundArgument, "Value", FormatDateTime(value), "'MinDate'", "'MaxDate'")); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidBoundArgument, nameof(Value), FormatDateTime(value), $"'{nameof(MinDate)}'", $"'{nameof(MaxDate)}'")); } string oldText = this.Text; diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DomainUpDown.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DomainUpDown.cs index 0709e062962..bfe76f55121 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/DomainUpDown.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/DomainUpDown.cs @@ -139,7 +139,7 @@ public int SelectedIndex { set { if (value < -1 || value >= Items.Count) { - throw new ArgumentOutOfRangeException(nameof(SelectedIndex), string.Format(SR.InvalidArgument, "SelectedIndex", (value).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidArgument, nameof(SelectedIndex), value)); } if (value != SelectedIndex) { @@ -645,7 +645,7 @@ public override void Remove(object item) { int index = IndexOf(item); if (index == -1) { - throw new ArgumentOutOfRangeException(nameof(item), string.Format(SR.InvalidArgument, "item", item.ToString())); + throw new ArgumentOutOfRangeException(nameof(item), item, string.Format(SR.InvalidArgument, nameof(item), item)); } else { RemoveAt(index); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/FlatButtonAppearance.cs b/src/System.Windows.Forms/src/System/Windows/Forms/FlatButtonAppearance.cs index 63296e844c7..716324628e2 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/FlatButtonAppearance.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/FlatButtonAppearance.cs @@ -46,7 +46,7 @@ public int BorderSize { } set { if (value < 0) - throw new ArgumentOutOfRangeException(nameof(BorderSize), value, string.Format(SR.InvalidLowBoundArgumentEx, "BorderSize", value.ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(BorderSize), value, 0)); if (borderSize != value) { borderSize = value; diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Help.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Help.cs index cb2acc30878..bf4d951bbb2 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Help.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Help.cs @@ -247,7 +247,7 @@ private static void ShowHTML10Help(Control parent, string url, HelpNavigator com SafeNativeMethods.HtmlHelp(handle, pathAndFileName, HH_DISPLAY_TEXT_POPUP, (NativeMethods.HH_POPUP)param); } else if (param.GetType() == typeof(int)) { - throw new ArgumentException(string.Format(SR.InvalidArgument, "param", "Integer")); + throw new ArgumentException(string.Format(SR.InvalidArgument, nameof(param), "Integer"), nameof(param)); } } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/HtmlElementCollection.cs b/src/System.Windows.Forms/src/System/Windows/Forms/HtmlElementCollection.cs index 9901d60f52b..15469934835 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/HtmlElementCollection.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/HtmlElementCollection.cs @@ -52,8 +52,8 @@ private UnsafeNativeMethods.IHTMLElementCollection NativeHtmlElementCollection { public HtmlElement this[int index] { get { //do some bounds checking here... - if (index < 0 || index >= this.Count) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidBoundArgument, "index", index, 0, this.Count - 1)); + if (index < 0 || index >= Count) { + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidBoundArgument, nameof(index), index, 0, Count - 1)); } if (this.NativeHtmlElementCollection != null) { diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/HtmlHistory.cs b/src/System.Windows.Forms/src/System/Windows/Forms/HtmlHistory.cs index 3aeb718e3bc..893d2d001c4 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/HtmlHistory.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/HtmlHistory.cs @@ -53,7 +53,7 @@ public int Length { /// public void Back(int numberBack) { if (numberBack < 0) { - throw new ArgumentOutOfRangeException(nameof(numberBack), string.Format(SR.InvalidLowBoundArgumentEx, "numberBack", numberBack.ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(numberBack), numberBack, string.Format(SR.InvalidLowBoundArgumentEx, nameof(numberBack), numberBack, 0)); } else if (numberBack > 0) { object oNumForward = (object)(-numberBack); @@ -64,7 +64,7 @@ public void Back(int numberBack) { /// public void Forward(int numberForward) { if (numberForward < 0) { - throw new ArgumentOutOfRangeException(nameof(numberForward), string.Format(SR.InvalidLowBoundArgumentEx, "numberForward", numberForward.ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(numberForward), numberForward, string.Format(SR.InvalidLowBoundArgumentEx, nameof(numberForward), numberForward, 0)); } else if (numberForward > 0) { object oNumForward = (object)numberForward; diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/HtmlWindowCollection.cs b/src/System.Windows.Forms/src/System/Windows/Forms/HtmlWindowCollection.cs index fa4163f783c..721c7c17322 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/HtmlWindowCollection.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/HtmlWindowCollection.cs @@ -38,8 +38,8 @@ private UnsafeNativeMethods.IHTMLFramesCollection2 NativeHTMLFramesCollection2 { /// public HtmlWindow this[int index] { get { - if (index < 0 || index >= this.Count) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidBoundArgument, "index", index, 0, this.Count - 1)); + if (index < 0 || index >= Count) { + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidBoundArgument, nameof(index), index, 0, Count - 1)); } object oIndex = (object)index; @@ -59,7 +59,7 @@ public HtmlWindow this[string windowId] { as UnsafeNativeMethods.IHTMLWindow2; } catch (COMException) { - throw new ArgumentException(string.Format(SR.InvalidArgument, "windowId", windowId)); + throw new ArgumentException(string.Format(SR.InvalidArgument, nameof(windowId), windowId), nameof(windowId)); } return (htmlWindow2 != null) ? new HtmlWindow(shimManager, htmlWindow2) : null; } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ImageList.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ImageList.cs index 18e94789dbe..3e66668854c 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/ImageList.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/ImageList.cs @@ -258,11 +258,11 @@ public Size ImageSize { // to keep people's systems from crashing. // if (value.Width <= 0 || value.Width > maxImageWidth) { - throw new ArgumentOutOfRangeException(nameof(value), string.Format(SR.InvalidBoundArgument, "ImageSize.Width", value.Width.ToString(CultureInfo.CurrentCulture), (1).ToString(CultureInfo.CurrentCulture), maxImageWidth.ToString())); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidBoundArgument, "ImageSize.Width", value.Width, 1, maxImageWidth)); } if (value.Height <= 0 || value.Height > maxImageHeight) { - throw new ArgumentOutOfRangeException(nameof(value), string.Format(SR.InvalidBoundArgument, "ImageSize.Height", value.Height.ToString(CultureInfo.CurrentCulture), (1).ToString(CultureInfo.CurrentCulture), maxImageHeight.ToString())); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidBoundArgument, "ImageSize.Height", value.Height, 1, maxImageHeight)); } if (imageSize.Width != value.Width || imageSize.Height != value.Height) { @@ -611,7 +611,7 @@ public void Draw(Graphics g, int x, int y, int index) { /// public void Draw(Graphics g, int x, int y, int width, int height, int index) { if (index < 0 || index >= Images.Count) - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", index.ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); IntPtr dc = g.GetHdc(); try { SafeNativeMethods.ImageList_DrawEx(new HandleRef(this, Handle), index, new HandleRef(g, dc), x, y, @@ -677,7 +677,7 @@ private static bool BitmapHasAlpha(BitmapData bmpData) { private Bitmap GetBitmap(int index) { if (index < 0 || index >= Images.Count) - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", index.ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); Bitmap result=null; @@ -802,7 +802,7 @@ private void PutImageInTempBitmap(int index, bool useSnapshot) { int count = SafeNativeMethods.ImageList_GetImageCount(handleUse); if (index < 0 || index >= count) - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString())); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); if (temp != null) { Size size = temp.Size; @@ -1098,12 +1098,12 @@ public Image this[int index] { get { if (index < 0 || index >= Count) - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", index.ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); return owner.GetBitmap(index); } set { if (index < 0 || index >= Count) - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", index.ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); if (value == null) { throw new ArgumentNullException(nameof(value)); @@ -1513,7 +1513,7 @@ void IList.Remove(object image) { /// public void RemoveAt(int index) { if (index < 0 || index >= Count) - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", index.ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); AssertInvariant(); bool ok = SafeNativeMethods.ImageList_Remove(new HandleRef(owner, owner.Handle), index); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Label.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Label.cs index 6747eed64f7..96832b5098c 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Label.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Label.cs @@ -511,7 +511,7 @@ public int ImageIndex { } set { if (value < -1) { - throw new ArgumentOutOfRangeException(nameof(ImageIndex), string.Format(SR.InvalidLowBoundArgumentEx, "ImageIndex", (value).ToString(CultureInfo.CurrentCulture), (-1).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(ImageIndex), value, -1)); } if (ImageIndex != value) { if (value != -1) { diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Layout/PropertyNames.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Layout/PropertyNames.cs index 224eb1b5d84..6009fd039e3 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Layout/PropertyNames.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Layout/PropertyNames.cs @@ -71,7 +71,7 @@ internal class PropertyNames { [SuppressMessage("Microsoft.Performance", "CA1802:UseLiteralsWhereAppropriate")] public static readonly string Image= "Image"; [SuppressMessage("Microsoft.Performance", "CA1802:UseLiteralsWhereAppropriate")] - public static readonly string ImageIndex= "ImageIndex"; + public static readonly string ImageIndex= nameof(ImageIndex); [SuppressMessage("Microsoft.Performance", "CA1802:UseLiteralsWhereAppropriate")] public static readonly string ImageScaling= "ImageScaling"; [SuppressMessage("Microsoft.Performance", "CA1802:UseLiteralsWhereAppropriate")] diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Layout/TableLayout.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Layout/TableLayout.cs index 7741c10f805..a92e1bfc0a0 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Layout/TableLayout.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Layout/TableLayout.cs @@ -1241,10 +1241,10 @@ private void SetElementBounds(ContainerInfo containerInfo, RectangleF displayRec internal IArrangedElement GetControlFromPosition (IArrangedElement container, int column, int row) { if (row < 0) { - throw new ArgumentException(string.Format(SR.InvalidArgument, "RowPosition", row.ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(row), row, string.Format(SR.InvalidArgument, "RowPosition", row)); } if (column < 0) { - throw new ArgumentException(string.Format(SR.InvalidArgument, "ColumnPosition", column.ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(column), column, string.Format(SR.InvalidArgument, "ColumnPosition", column)); } ArrangedElementCollection children = container.Children; ContainerInfo containerInfo = GetContainerInfo(container); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ListBox.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ListBox.cs index 473af5eee8f..9e90c4333bc 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/ListBox.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/ListBox.cs @@ -288,10 +288,11 @@ public int ColumnWidth { } set { - if (value < 0) { - throw new ArgumentException(string.Format(SR.InvalidLowBoundArgumentEx, "value", - (value).ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(value), value, 0)); } + if (columnWidth != value) { columnWidth = value; // if it's zero, we need to reset, and only way to do @@ -610,7 +611,7 @@ public virtual int ItemHeight { set { if (value < 1 || value > 255) { - throw new ArgumentOutOfRangeException(nameof(ItemHeight), string.Format(SR.InvalidExBoundArgument, "ItemHeight", (value).ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture), "256")); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidExBoundArgument, nameof(ItemHeight), value, 0, 256)); } if (itemHeight != value) { itemHeight = value; @@ -868,11 +869,11 @@ public override int SelectedIndex { int itemCount = (itemsCollection == null) ? 0 : itemsCollection.Count; if (value < -1 || value >= itemCount) { - throw new ArgumentOutOfRangeException(nameof(SelectedIndex), string.Format(SR.InvalidArgument, "SelectedIndex", (value).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidArgument, nameof(SelectedIndex), value)); } if (selectionMode == SelectionMode.None) { - throw new ArgumentException(SR.ListBoxInvalidSelectionMode, "SelectedIndex"); + throw new ArgumentException(SR.ListBoxInvalidSelectionMode, nameof(value)); } if (selectionMode == SelectionMode.One && value != -1) { @@ -1444,7 +1445,7 @@ public int GetItemHeight(int index) { // no items. // if (index < 0 || (index > 0 && index >= itemCount)) - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); if (drawMode != DrawMode.OwnerDrawVariable) index = 0; @@ -2080,7 +2081,7 @@ protected override void SetItemCore(int index, object value) { public void SetSelected(int index, bool value) { int itemCount = (itemsCollection == null) ? 0: itemsCollection.Count; if (index < 0 || index >= itemCount) - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); if (selectionMode == SelectionMode.None) throw new InvalidOperationException(SR.ListBoxInvalidSelectionMode); @@ -3089,7 +3090,7 @@ internal void AddRangeInternal(ICollection items) { public virtual object this[int index] { get { if (index < 0 || index >= InnerArray.GetCount(0)) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } return InnerArray.GetItem(index, 0); @@ -3197,7 +3198,7 @@ public void Insert(int index, object item) { owner.CheckNoDataSource(); if (index < 0 || index > InnerArray.GetCount(0)) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } if (item == null) { @@ -3253,7 +3254,7 @@ public void RemoveAt(int index) { owner.CheckNoDataSource(); if (index < 0 || index >= InnerArray.GetCount(0)) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } owner.UpdateMaxItemWidth(InnerArray.GetItem(index, 0), true); @@ -3275,7 +3276,7 @@ internal void SetItemInternal(int index, object value) { } if (index < 0 || index >= InnerArray.GetCount(0)) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } owner.UpdateMaxItemWidth(InnerArray.GetItem(index, 0), true); @@ -3569,7 +3570,7 @@ public void Remove(int item) { /// public void RemoveAt(int index) { if (index < 0 || index >= count) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } count--; @@ -3597,7 +3598,7 @@ public int this[int index] { set { if (index < 0 || index >= count) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } innerArray[index] = (int)value; owner.UpdateCustomTabOffsets(); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ListView.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ListView.cs index 3fc3393a163..ec387a94b06 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/ListView.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/ListView.cs @@ -1768,7 +1768,7 @@ public int VirtualListSize { } set { if (value < 0) - throw new System.ArgumentException(string.Format(SR.ListViewVirtualListSizeInvalidArgument, "value", (value.ToString(CultureInfo.CurrentCulture)))); + throw new System.ArgumentException(string.Format(SR.ListViewVirtualListSizeInvalidArgument, "value", (value))); if (value == virtualListSize) return; bool keepTopItem = this.IsHandleCreated && VirtualMode && this.View == View.Details && !this.DesignMode; @@ -2149,9 +2149,7 @@ public void ArrangeIcons(ListViewAlignment value) { break; default: - throw new ArgumentException(string.Format(SR.InvalidArgument, - "value", - ((value).ToString()))); + throw new ArgumentException(string.Format(SR.InvalidArgument, nameof(value), value), nameof(value)); } if (!VirtualMode && sorting != SortOrder.None) { @@ -2937,7 +2935,7 @@ private void EnsureDefaultGroup() { /// public void EnsureVisible(int index) { if (index < 0 || index >= Items.Count) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } if (IsHandleCreated) UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.LVM_ENSUREVISIBLE, index, 0); @@ -2968,7 +2966,7 @@ public ListViewItem FindItemWithText(string text, bool includeSubItemsInSearch, public ListViewItem FindItemWithText(string text, bool includeSubItemsInSearch, int startIndex, bool isPrefixSearch) { if (startIndex < 0 || startIndex >= this.Items.Count) { - throw new ArgumentOutOfRangeException(nameof(startIndex), string.Format(SR.InvalidArgument, "startIndex", (startIndex).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(startIndex), startIndex, string.Format(SR.InvalidArgument, nameof(startIndex), startIndex)); } return FindItem(true, text, isPrefixSearch, new Point(0,0), SearchDirectionHint.Down, startIndex, includeSubItemsInSearch); } @@ -2990,7 +2988,7 @@ public ListViewItem FindNearestItem(SearchDirectionHint searchDirection, int x, } if ( searchDirection < SearchDirectionHint.Left || searchDirection > SearchDirectionHint.Down) { - throw new ArgumentOutOfRangeException(nameof(searchDirection), string.Format(SR.InvalidArgument, "searchDirection", (searchDirection).ToString())); + throw new ArgumentOutOfRangeException(nameof(searchDirection), searchDirection, string.Format(SR.InvalidArgument, nameof(searchDirection), searchDirection)); } // the win32 ListView::FindNearestItem does some pretty weird things to determine the nearest item. @@ -3267,7 +3265,7 @@ internal int GetItemState(int index) { internal int GetItemState(int index, int mask) { if (index < 0 || ((this.VirtualMode && index >= this.VirtualListSize) || (!this.VirtualMode && index >= itemCount))) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } Debug.Assert(IsHandleCreated, "How did we add items without a handle?"); @@ -3288,7 +3286,7 @@ public Rectangle GetItemRect(int index) { /// public Rectangle GetItemRect(int index, ItemBoundsPortion portion) { if (index < 0 || index >= this.Items.Count) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } //valid values are 0x0 to 0x3 if (!ClientUtils.IsEnumValid(portion, (int)portion, (int)ItemBoundsPortion.Entire, (int)ItemBoundsPortion.ItemOnly)){ @@ -3303,9 +3301,7 @@ public Rectangle GetItemRect(int index, ItemBoundsPortion portion) { NativeMethods.RECT itemrect = new NativeMethods.RECT(); itemrect.left = (int)portion; if (unchecked( (int) (long)SendMessage(NativeMethods.LVM_GETITEMRECT, index, ref itemrect)) == 0) - throw new ArgumentException(string.Format(SR.InvalidArgument, - "index", - (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); return Rectangle.FromLTRB(itemrect.left, itemrect.top, itemrect.right, itemrect.bottom); } @@ -3376,12 +3372,12 @@ internal Rectangle GetSubItemRect(int itemIndex, int subItemIndex, ItemBoundsPor return Rectangle.Empty; } if (itemIndex < 0 || itemIndex >= this.Items.Count) { - throw new ArgumentOutOfRangeException(nameof(itemIndex), string.Format(SR.InvalidArgument, "itemIndex", (itemIndex).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(itemIndex), itemIndex, string.Format(SR.InvalidArgument, nameof(itemIndex), itemIndex)); } int subItemCount = Items[itemIndex].SubItems.Count; if (subItemIndex < 0 || subItemIndex >= subItemCount) { - throw new ArgumentOutOfRangeException(nameof(subItemIndex), string.Format(SR.InvalidArgument, "subItemIndex", (subItemIndex).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(subItemIndex), subItemIndex, string.Format(SR.InvalidArgument, nameof(subItemIndex), subItemIndex)); } //valid values are 0x0 to 0x3 if (!ClientUtils.IsEnumValid(portion, (int)portion, (int)ItemBoundsPortion.Entire, (int)ItemBoundsPortion.ItemOnly)) @@ -3397,9 +3393,7 @@ internal Rectangle GetSubItemRect(int itemIndex, int subItemIndex, ItemBoundsPor itemrect.left = (int)portion; itemrect.top = subItemIndex; if (unchecked( (int) (long)SendMessage(NativeMethods.LVM_GETSUBITEMRECT, itemIndex, ref itemrect)) == 0) - throw new ArgumentException(string.Format(SR.InvalidArgument, - "itemIndex", - (itemIndex).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(itemIndex), itemIndex, string.Format(SR.InvalidArgument, nameof(itemIndex), itemIndex)); Rectangle result = Rectangle.FromLTRB(itemrect.left, itemrect.top, itemrect.right, itemrect.bottom); @@ -4531,22 +4525,22 @@ public void RedrawItems(int startIndex, int endIndex, bool invalidateOnly) { if (startIndex < 0 || startIndex >= this.VirtualListSize) { - throw new ArgumentOutOfRangeException(nameof(startIndex), string.Format(SR.InvalidArgument, "startIndex", (startIndex).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(startIndex), startIndex, string.Format(SR.InvalidArgument, nameof(startIndex), startIndex)); } if (endIndex < 0 || endIndex >= this.VirtualListSize) { - throw new ArgumentOutOfRangeException(nameof(endIndex), string.Format(SR.InvalidArgument, "endIndex", (endIndex).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(endIndex), endIndex, string.Format(SR.InvalidArgument, nameof(endIndex), endIndex)); } } else { if (startIndex < 0 || startIndex >= this.Items.Count) { - throw new ArgumentOutOfRangeException(nameof(startIndex), string.Format(SR.InvalidArgument, "startIndex", (startIndex).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(startIndex), startIndex, string.Format(SR.InvalidArgument, nameof(startIndex), startIndex)); } if (endIndex < 0 || endIndex >= this.Items.Count) { - throw new ArgumentOutOfRangeException(nameof(endIndex), string.Format(SR.InvalidArgument, "endIndex", (endIndex).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(endIndex), endIndex, string.Format(SR.InvalidArgument, nameof(endIndex), endIndex)); } } if (startIndex > endIndex) @@ -4761,7 +4755,7 @@ internal void SetColumnWidth(int columnIndex, ColumnHeaderAutoResizeStyle header if ((columnIndex < 0) || (columnIndex >= 0 && this.columnHeaders == null) || (columnIndex >= this.columnHeaders.Length)) { - throw new ArgumentOutOfRangeException(nameof(columnIndex), string.Format(SR.InvalidArgument, "columnIndex", (columnIndex).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(columnIndex), columnIndex, string.Format(SR.InvalidArgument, nameof(columnIndex), columnIndex)); } //valid values are 0x0 to 0x2 @@ -4894,7 +4888,7 @@ internal void SetToolTip(ToolTip toolTip, string toolTipCaption) { internal void SetItemImage(int index, int image) { if (index < 0 || ((this.VirtualMode && index >= this.VirtualListSize) || (!this.VirtualMode && index >= itemCount))) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } if (this.IsHandleCreated) { NativeMethods.LVITEM lvItem = new NativeMethods.LVITEM(); @@ -4907,7 +4901,7 @@ internal void SetItemImage(int index, int image) { internal void SetItemIndentCount(int index, int indentCount) { if (index < 0 || ((this.VirtualMode && index >= this.VirtualListSize) || (!this.VirtualMode && index >= itemCount))) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } if (this.IsHandleCreated) { NativeMethods.LVITEM lvItem = new NativeMethods.LVITEM(); @@ -4922,7 +4916,7 @@ internal void SetItemPosition(int index, int x, int y) { if (VirtualMode) return; if (index < 0 || index >= itemCount) - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); Debug.Assert(IsHandleCreated, "How did we add items without a handle?"); @@ -4934,7 +4928,7 @@ internal void SetItemPosition(int index, int x, int y) { internal void SetItemState(int index, int state, int mask) { if (index < -1 || ((this.VirtualMode && index >= this.VirtualListSize) || (!this.VirtualMode && index >= itemCount))) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } Debug.Assert(index == -1 || this.IsHandleCreated, "How did we add items without a handle?"); @@ -6267,7 +6261,7 @@ public int this[int index] { get { if (index < 0) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } // Loop through the main collection until we find the right index. @@ -6286,7 +6280,7 @@ public int this[int index] { } // Should never get to this point. - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } } @@ -6799,7 +6793,7 @@ public int this[int index] { get { if (index < 0 || index >= Count) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } if (owner.IsHandleCreated) { @@ -6912,7 +6906,7 @@ int IList.Add(object value) } else { - throw new ArgumentException(string.Format(SR.InvalidArgument, "value", ((value).ToString()))); + throw new ArgumentException(string.Format(SR.InvalidArgument, nameof(value), value), nameof(value)); } } @@ -6938,7 +6932,7 @@ void IList.Remove(object value) } else { - throw new ArgumentException(string.Format(SR.InvalidArgument, "value", ((value).ToString()))); + throw new ArgumentException(string.Format(SR.InvalidArgument, nameof(value), value), nameof(value)); } } @@ -6955,7 +6949,7 @@ public int Add(int itemIndex) { if (itemIndex < 0 || itemIndex >= this.owner.VirtualListSize) { - throw new ArgumentOutOfRangeException(nameof(itemIndex), string.Format(SR.InvalidArgument, "itemIndex", (itemIndex).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(itemIndex), itemIndex, string.Format(SR.InvalidArgument, nameof(itemIndex), itemIndex)); } if (this.owner.IsHandleCreated) { @@ -6971,7 +6965,7 @@ public int Add(int itemIndex) { if (itemIndex < 0 || itemIndex >= this.owner.Items.Count) { - throw new ArgumentOutOfRangeException(nameof(itemIndex), string.Format(SR.InvalidArgument, "itemIndex", (itemIndex).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(itemIndex), itemIndex, string.Format(SR.InvalidArgument, nameof(itemIndex), itemIndex)); } this.owner.Items[itemIndex].Selected = true; return this.Count; @@ -7016,7 +7010,7 @@ public void Remove(int itemIndex) { if (itemIndex < 0 || itemIndex >= this.owner.VirtualListSize) { - throw new ArgumentOutOfRangeException(nameof(itemIndex), string.Format(SR.InvalidArgument, "itemIndex", (itemIndex).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(itemIndex), itemIndex, string.Format(SR.InvalidArgument, nameof(itemIndex), itemIndex)); } if (this.owner.IsHandleCreated) { @@ -7027,7 +7021,7 @@ public void Remove(int itemIndex) { if (itemIndex < 0 || itemIndex >= this.owner.Items.Count) { - throw new ArgumentOutOfRangeException(nameof(itemIndex), string.Format(SR.InvalidArgument, "itemIndex", (itemIndex).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(itemIndex), itemIndex, string.Format(SR.InvalidArgument, nameof(itemIndex), itemIndex)); } this.owner.Items[itemIndex].Selected = false; } @@ -7123,7 +7117,7 @@ public ListViewItem this[int index] { } if (index < 0 || index >= Count) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } if (owner.IsHandleCreated) { @@ -7419,7 +7413,7 @@ public ColumnHeaderCollection(ListView owner) { public virtual ColumnHeader this[int index] { get { if (owner.columnHeaders == null || index < 0 || index >= owner.columnHeaders.Length) - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); return owner.columnHeaders[index]; } } @@ -7764,7 +7758,7 @@ int IList.IndexOf(object value) { /// public void Insert(int index, ColumnHeader value) { if (index < 0 || index > Count) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } owner.InsertColumn(index, value); } @@ -7849,7 +7843,7 @@ public void Insert(int index, string key, string text, int width, HorizontalAlig /// public virtual void RemoveAt(int index) { if (owner.columnHeaders == null || index < 0 || index >= owner.columnHeaders.Length) - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); int w = owner.columnHeaders[index].Width; // Update width before detaching from ListView @@ -7858,9 +7852,7 @@ public virtual void RemoveAt(int index) { int retval = unchecked( (int) (long)owner.SendMessage(NativeMethods.LVM_DELETECOLUMN, index, 0)); if (0 == retval) - throw new ArgumentException(string.Format(SR.InvalidArgument, - "index", - (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } // we need to update the display indices @@ -8031,14 +8023,14 @@ public bool IsReadOnly { public virtual ListViewItem this[int index] { get { if (index < 0 || index >= InnerList.Count) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } return InnerList[index]; } set { if (index < 0 || index >= InnerList.Count) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } InnerList[index] = value; @@ -8349,7 +8341,7 @@ private bool IsValidIndex(int index) { /// public ListViewItem Insert(int index, ListViewItem item) { if (index < 0 || index > Count) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } InnerList.Insert(index, item); return item; @@ -8413,7 +8405,7 @@ public virtual void Remove(ListViewItem item) { /// public virtual void RemoveAt(int index) { if (index < 0 || index >= Count) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } InnerList.RemoveAt(index); @@ -8489,7 +8481,7 @@ public ListViewItem this[int displayIndex] { } else { if (displayIndex < 0 || displayIndex >= owner.itemCount) - throw new ArgumentOutOfRangeException(nameof(displayIndex), string.Format(SR.InvalidArgument, "displayIndex", (displayIndex).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(displayIndex), displayIndex, string.Format(SR.InvalidArgument, nameof(displayIndex), displayIndex)); if (owner.IsHandleCreated && !owner.ListViewHandleDestroyed) { return (ListViewItem)owner.listItemsTable[DisplayIndexToID(displayIndex)]; @@ -8507,7 +8499,7 @@ public ListViewItem this[int displayIndex] { } if (displayIndex < 0 || displayIndex >= owner.itemCount) - throw new ArgumentOutOfRangeException(nameof(displayIndex), string.Format(SR.InvalidArgument, "displayIndex", (displayIndex).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(displayIndex), displayIndex, string.Format(SR.InvalidArgument, nameof(displayIndex), displayIndex)); if (this.owner.ExpectingMouseUp) { this.owner.ItemCollectionChangedInMouseDown = true; @@ -8710,7 +8702,7 @@ public ListViewItem Insert(int index, ListViewItem item) { } if (index < 0 || index > count) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } if (owner.VirtualMode) { @@ -8767,7 +8759,7 @@ public void RemoveAt(int index) { } if (index < 0 || index >= owner.itemCount) - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); Debug.Assert(!this.owner.FlipViewToLargeIconAndSmallIcon || this.Count == 0, "the FlipView... bit is turned off after adding 1 item."); @@ -8785,9 +8777,7 @@ public void RemoveAt(int index) { int retval = unchecked( (int) (long)owner.SendMessage(NativeMethods.LVM_DELETEITEM, index, 0)); if (0 == retval) - throw new ArgumentException(string.Format(SR.InvalidArgument, - "index", - (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } else { Debug.Assert(owner.listItemsArray != null, "listItemsArray is null, but the handle isn't created"); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ListViewItem.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ListViewItem.cs index b7cf6c6b50e..e80eb59d093 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/ListViewItem.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/ListViewItem.cs @@ -472,8 +472,9 @@ public int ImageIndex { return this.ImageIndexer.Index; } set { - if (value < -1) { - throw new ArgumentOutOfRangeException(nameof(ImageIndex), string.Format(SR.InvalidLowBoundArgumentEx, "ImageIndex", value.ToString(CultureInfo.CurrentCulture), (-1).ToString(CultureInfo.CurrentCulture))); + if (value < -1) + { + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(ImageIndex), value, -1)); } ImageIndexer.Index = value; @@ -725,7 +726,7 @@ public int StateImageIndex { } set { if (value < -1 || value > 14) - throw new ArgumentOutOfRangeException(nameof(StateImageIndex), string.Format(SR.InvalidArgument, "StateImageIndex", (value).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidArgument, nameof(StateImageIndex), value)); if (listView != null && listView.IsHandleCreated) { this.state[StateImageMaskSet] = (value == -1 ? 0 : 1); @@ -1177,7 +1178,7 @@ protected virtual void Deserialize(SerializationInfo info, StreamingContext cont if (entry.Name == "Text") { Text = info.GetString(entry.Name); } - else if (entry.Name == "ImageIndex") { + else if (entry.Name == nameof(ImageIndex)) { imageIndex = info.GetInt32(entry.Name); } else if (entry.Name == "ImageKey") { @@ -1239,7 +1240,7 @@ protected virtual void Deserialize(SerializationInfo info, StreamingContext cont /// protected virtual void Serialize(SerializationInfo info, StreamingContext context) { info.AddValue("Text", Text); - info.AddValue("ImageIndex", ImageIndexer.Index); + info.AddValue(nameof(ImageIndex), ImageIndexer.Index); if (!string.IsNullOrEmpty(ImageIndexer.Key)) { info.AddValue("ImageKey", ImageIndexer.Key); } @@ -1650,14 +1651,14 @@ public bool IsReadOnly { public ListViewSubItem this[int index] { get { if (index < 0 || index >= Count) - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); return owner.subItems[index]; } set { if (index < 0 || index >= Count) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } if (value == null) { diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Menu.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Menu.cs index 19d084b2409..0712c7691b8 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Menu.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Menu.cs @@ -686,7 +686,7 @@ public MenuItemCollection(Menu owner) { public virtual MenuItem this[int index] { get { if (index < 0 || index >= owner.ItemCount) - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); return owner.items[index]; } // set not supported @@ -850,7 +850,7 @@ public virtual int Add(int index, MenuItem item) { // Validate our index if (index < 0 || index > owner.ItemCount) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument,"index",(index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } if (owner.items == null || owner.items.Length == owner.ItemCount) { @@ -1093,7 +1093,7 @@ public IEnumerator GetEnumerator() { /// public virtual void RemoveAt(int index) { if (index < 0 || index >= owner.ItemCount) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument,"index",(index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } MenuItem item = owner.items[index]; diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/MenuItem.cs b/src/System.Windows.Forms/src/System/Windows/Forms/MenuItem.cs index 7b754ab1e72..3036ebad490 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/MenuItem.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/MenuItem.cs @@ -353,7 +353,7 @@ public int Index { int oldIndex = Index; if (oldIndex >= 0) { if (value < 0 || value >= menu.ItemCount) { - throw new ArgumentOutOfRangeException(nameof(Index), string.Format(SR.InvalidArgument, "Index", (value).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidArgument, nameof(Index), value)); } if (value != oldIndex) { diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/MonthCalendar.cs b/src/System.Windows.Forms/src/System/Windows/Forms/MonthCalendar.cs index 76576ae8df7..352a580d179 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/MonthCalendar.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/MonthCalendar.cs @@ -517,7 +517,7 @@ public DateTime MaxDate { set { if (value != maxDate) { if (value < DateTimePicker.EffectiveMinDate(minDate)) { - throw new ArgumentOutOfRangeException(nameof(MaxDate), string.Format(SR.InvalidLowBoundArgumentEx, "MaxDate", FormatDate(value), "MinDate")); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(MaxDate), FormatDate(value), nameof(MinDate))); } maxDate = value; SetRange(); @@ -542,13 +542,13 @@ public int MaxSelectionCount { } set { if (value < 1) { - throw new ArgumentOutOfRangeException(nameof(MaxSelectionCount), string.Format(SR.InvalidLowBoundArgumentEx, "MaxSelectionCount", (value).ToString("D", CultureInfo.CurrentCulture), (1).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(MaxSelectionCount), value.ToString("D"), 1)); } if (value != maxSelectionCount) { if (IsHandleCreated) { if (unchecked( (int) (long)SendMessage(NativeMethods.MCM_SETMAXSELCOUNT, value, 0)) == 0) - throw new ArgumentException(string.Format(SR.MonthCalendarMaxSelCount, (value).ToString("D", CultureInfo.CurrentCulture)), "MaxSelectionCount"); + throw new ArgumentException(string.Format(SR.MonthCalendarMaxSelCount, value.ToString("D")), nameof(value)); } maxSelectionCount = value; } @@ -572,13 +572,13 @@ public DateTime MinDate { set { if (value != minDate) { if (value > DateTimePicker.EffectiveMaxDate(maxDate)) { - throw new ArgumentOutOfRangeException(nameof(MinDate), string.Format(SR.InvalidHighBoundArgument, "MinDate", FormatDate(value), "MaxDate")); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidHighBoundArgument, nameof(MinDate), FormatDate(value), nameof(MaxDate))); } // If trying to set the minimum less than DateTimePicker.MinimumDateTime, throw // an exception. if (value < DateTimePicker.MinimumDateTime) { - throw new ArgumentOutOfRangeException(nameof(MinDate), string.Format(SR.InvalidLowBoundArgumentEx, "MinDate", FormatDate(value), FormatDate(DateTimePicker.MinimumDateTime))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(MinDate), FormatDate(value), FormatDate(DateTimePicker.MinimumDateTime))); } minDate = value; @@ -708,10 +708,10 @@ public int ScrollChange { if (scrollChange != value) { if (value < 0) { - throw new ArgumentOutOfRangeException(nameof(ScrollChange), string.Format(SR.InvalidLowBoundArgumentEx, "ScrollChange", (value).ToString("D", CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(ScrollChange), value.ToString("D"), 0)); } if (value > MaxScrollChange) { - throw new ArgumentOutOfRangeException(nameof(ScrollChange), string.Format(SR.InvalidHighBoundArgumentEx, "ScrollChange", (value).ToString("D", CultureInfo.CurrentCulture), (MaxScrollChange).ToString("D", CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidHighBoundArgumentEx, nameof(ScrollChange), value.ToString("D"), MaxScrollChange.ToString("D"))); } if (IsHandleCreated) { @@ -742,10 +742,10 @@ public DateTime SelectionEnd { // Keep SelectionEnd within min and max if (value < MinDate) { - throw new ArgumentOutOfRangeException(nameof(SelectionEnd), string.Format(SR.InvalidLowBoundArgumentEx, "SelectionEnd", FormatDate(value), "MinDate")); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(SelectionEnd), FormatDate(value), nameof(MinDate))); } if (value > MaxDate) { - throw new ArgumentOutOfRangeException(nameof(SelectionEnd), string.Format(SR.InvalidHighBoundArgumentEx, "SelectionEnd", FormatDate(value), "MaxDate")); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidHighBoundArgumentEx, nameof(SelectionEnd), FormatDate(value), nameof(MaxDate))); } // If we've moved SelectionEnd before SelectionStart, move SelectionStart back @@ -786,10 +786,10 @@ public DateTime SelectionStart { // Keep SelectionStart within min and max // if (value < minDate) { - throw new ArgumentOutOfRangeException(nameof(SelectionStart), string.Format(SR.InvalidLowBoundArgumentEx, "SelectionStart", FormatDate(value), "MinDate")); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(SelectionStart), FormatDate(value), nameof(MinDate))); } if (value > maxDate) { - throw new ArgumentOutOfRangeException(nameof(SelectionStart), string.Format(SR.InvalidHighBoundArgumentEx, "SelectionStart", FormatDate(value), "MaxDate")); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidHighBoundArgumentEx, nameof(SelectionStart), FormatDate(value), nameof(MaxDate))); } // If we've moved SelectionStart beyond SelectionEnd, move SelectionEnd forward @@ -994,12 +994,12 @@ public DateTime TodayDate { // throw if trying to set the TodayDate to a value greater than MaxDate if (DateTime.Compare(value, maxDate) > 0) { - throw new ArgumentOutOfRangeException(nameof(TodayDate), string.Format(SR.InvalidHighBoundArgumentEx, "TodayDate", FormatDate(value), FormatDate(maxDate))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidHighBoundArgumentEx, nameof(TodayDate), FormatDate(value), FormatDate(maxDate))); } // throw if trying to set the TodayDate to a value less than MinDate if (DateTime.Compare(value, minDate) < 0) { - throw new ArgumentOutOfRangeException(nameof(TodayDate), string.Format(SR.InvalidLowBoundArgument, "TodayDate", FormatDate(value), FormatDate(minDate))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgument, nameof(TodayDate), FormatDate(value), FormatDate(minDate))); } todayDate = value.Date; @@ -1976,10 +1976,10 @@ public void SetCalendarDimensions(int x, int y) { public void SetDate(DateTime date) { if (date.Ticks < minDate.Ticks) { - throw new ArgumentOutOfRangeException(nameof(date), string.Format(SR.InvalidLowBoundArgumentEx, "date", FormatDate(date), "MinDate")); + throw new ArgumentOutOfRangeException(nameof(date), date, string.Format(SR.InvalidLowBoundArgumentEx, nameof(date), FormatDate(date), nameof(MinDate))); } if (date.Ticks > maxDate.Ticks) { - throw new ArgumentOutOfRangeException(nameof(date), string.Format(SR.InvalidHighBoundArgumentEx, "date", FormatDate(date), "MaxDate")); + throw new ArgumentOutOfRangeException(nameof(date), date, string.Format(SR.InvalidHighBoundArgumentEx, nameof(date), FormatDate(date), nameof(MaxDate))); } SetSelectionRange(date, date); @@ -1995,16 +1995,16 @@ public void SetSelectionRange(DateTime date1, DateTime date2) { // Keep the dates within the min and max dates if (date1.Ticks < minDate.Ticks) { - throw new ArgumentOutOfRangeException(nameof(date1), string.Format(SR.InvalidLowBoundArgumentEx, "SelectionStart", FormatDate(date1), "MinDate")); + throw new ArgumentOutOfRangeException(nameof(date1), date1, string.Format(SR.InvalidLowBoundArgumentEx, nameof(SelectionStart), FormatDate(date1), nameof(MinDate))); } if (date1.Ticks > maxDate.Ticks) { - throw new ArgumentOutOfRangeException(nameof(date1), string.Format(SR.InvalidHighBoundArgumentEx, "SelectionEnd", FormatDate(date1), "MaxDate")); + throw new ArgumentOutOfRangeException(nameof(date1), date1, string.Format(SR.InvalidHighBoundArgumentEx, nameof(SelectionEnd), FormatDate(date1), nameof(MaxDate))); } if (date2.Ticks < minDate.Ticks) { - throw new ArgumentOutOfRangeException(nameof(date2), string.Format(SR.InvalidLowBoundArgumentEx, "SelectionStart", FormatDate(date2), "MinDate")); + throw new ArgumentOutOfRangeException(nameof(date2), date2, string.Format(SR.InvalidLowBoundArgumentEx, nameof(SelectionStart), FormatDate(date2), nameof(MinDate))); } if (date2.Ticks > maxDate.Ticks) { - throw new ArgumentOutOfRangeException(nameof(date2), string.Format(SR.InvalidHighBoundArgumentEx, "SelectionEnd", FormatDate(date2), "MaxDate")); + throw new ArgumentOutOfRangeException(nameof(date2), date2, string.Format(SR.InvalidHighBoundArgumentEx, nameof(SelectionEnd), FormatDate(date2), nameof(MaxDate))); } // If date1 > date2, we just select date2 (compat) diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/NotifyIcon.cs b/src/System.Windows.Forms/src/System/Windows/Forms/NotifyIcon.cs index f37ae90ad51..270e4f40fdd 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/NotifyIcon.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/NotifyIcon.cs @@ -667,7 +667,7 @@ public void ShowBalloonTip(int timeout) { public void ShowBalloonTip(int timeout, string tipTitle, string tipText, ToolTipIcon tipIcon) { if (timeout < 0) { - throw new ArgumentOutOfRangeException(nameof(timeout), string.Format(SR.InvalidArgument, "timeout", (timeout).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(timeout), timeout, string.Format(SR.InvalidArgument, nameof(timeout), timeout)); } if (string.IsNullOrEmpty(tipText)) diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/NumericUpDown.cs b/src/System.Windows.Forms/src/System/Windows/Forms/NumericUpDown.cs index c21157084bf..9cfb0d2fd0f 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/NumericUpDown.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/NumericUpDown.cs @@ -135,7 +135,7 @@ public int DecimalPlaces { set { if (value < 0 || value > 99) { - throw new ArgumentOutOfRangeException(nameof(DecimalPlaces), string.Format(SR.InvalidBoundArgument, "DecimalPlaces", value.ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture), "99")); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidBoundArgument, nameof(DecimalPlaces), value, 0, 99)); } decimalPlaces = value; UpdateEditText(); @@ -186,8 +186,8 @@ public decimal Increment { } set { - if (value < (decimal)0.0) { - throw new ArgumentOutOfRangeException(nameof(Increment), string.Format(SR.InvalidArgument, "Increment", value.ToString(CultureInfo.CurrentCulture))); + if (value < 0.0m) { + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidArgument, nameof(Increment), value)); } else { this.increment = value; @@ -362,7 +362,7 @@ public decimal Value { if (value != currentValue) { if (!initializing && ((value < minimum) || (value > maximum))) { - throw new ArgumentOutOfRangeException(nameof(Value), string.Format(SR.InvalidBoundArgument, "Value", value.ToString(CultureInfo.CurrentCulture), "'Minimum'", "'Maximum'")); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidBoundArgument, nameof(Value), value, $"'{nameof(Minimum)}'", $"'{nameof(Maximum)}'")); } else { currentValue = value; diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Printing/PrintPreviewControl.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Printing/PrintPreviewControl.cs index dde328530ac..52d63fcca54 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Printing/PrintPreviewControl.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Printing/PrintPreviewControl.cs @@ -145,7 +145,7 @@ public int Columns { get { return columns;} set { if (value < 1 ) { - throw new ArgumentOutOfRangeException(nameof(Columns), string.Format(SR.InvalidLowBoundArgumentEx, "Columns", value.ToString(CultureInfo.CurrentCulture), (1).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(Columns), value, 1)); } columns = value; @@ -206,7 +206,7 @@ public int Rows { set { if (value < 1 ) { - throw new ArgumentOutOfRangeException(nameof(Rows), string.Format(SR.InvalidLowBoundArgumentEx, "Rows", value.ToString(CultureInfo.CurrentCulture), (1).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(Rows), value, 1)); } rows = value; @@ -287,7 +287,7 @@ public int StartPage { } set { if (value < 0 ) { - throw new ArgumentOutOfRangeException(nameof(StartPage), string.Format(SR.InvalidLowBoundArgumentEx, "StartPage", value.ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(StartPage), value, 0)); } int oldValue = StartPage; startPage = value; diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ProgressBar.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ProgressBar.cs index 7691d2d2b3b..5576ce62689 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/ProgressBar.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/ProgressBar.cs @@ -387,7 +387,7 @@ public int Maximum { // Message: '%1' is not a valid value for '%0'. '%0' must be greater than %2. // Should this set a boundary for the top end too? if (value < 0) - throw new ArgumentOutOfRangeException(nameof(Maximum), string.Format(SR.InvalidLowBoundArgumentEx, "Maximum", value.ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(Maximum), value, 0)); if (minimum > value) minimum = value; @@ -425,7 +425,7 @@ public int Minimum { // Message: '%1' is not a valid value for '%0'. '%0' must be greater than %2. // Should this set a boundary for the top end too? if (value < 0) - throw new ArgumentOutOfRangeException(nameof(Minimum), string.Format(SR.InvalidLowBoundArgumentEx, "Minimum", value.ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(Minimum), value, 0)); if (maximum < value) maximum = value; minimum = value; @@ -612,7 +612,7 @@ public int Value { set { if (this.value != value) { if ((value < minimum) || (value > maximum)) - throw new ArgumentOutOfRangeException(nameof(Value), string.Format(SR.InvalidBoundArgument, "Value", value.ToString(CultureInfo.CurrentCulture), "'minimum'", "'maximum'")); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidBoundArgument, nameof(Value), value, "'minimum'", "'maximum'")); this.value = value; UpdatePos() ; } @@ -855,7 +855,7 @@ internal override bool SupportsUiaProviders { public override string ToString() { string s = base.ToString(); - return s + ", Minimum: " + Minimum.ToString(CultureInfo.CurrentCulture) + ", Maximum: " + Maximum.ToString(CultureInfo.CurrentCulture) + ", Value: " + Value.ToString(CultureInfo.CurrentCulture); + return s + ", Minimum: " + Minimum.ToString(CultureInfo.CurrentCulture) + ", Maximum: " + Maximum.ToString(CultureInfo.CurrentCulture) + ", Value: " + value; } /// diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/RichTextBox.cs b/src/System.Windows.Forms/src/System/Windows/Forms/RichTextBox.cs index 33b78ceda55..a9475ecd4a3 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/RichTextBox.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/RichTextBox.cs @@ -287,7 +287,7 @@ public int BulletIndent { set { if (value < 0) { - throw new ArgumentOutOfRangeException(nameof(BulletIndent), string.Format(SR.InvalidArgument, "BulletIndent", (value).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidArgument, nameof(BulletIndent), value)); } this.bulletIndent = value; @@ -657,7 +657,7 @@ public int RightMargin { set { if (this.rightMargin != value) { if (value < 0) - throw new ArgumentOutOfRangeException(nameof(RightMargin), string.Format(SR.InvalidLowBoundArgumentEx, "RightMargin", value.ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(RightMargin), value, 0)); this.rightMargin = value; if (value == 0) { @@ -917,7 +917,7 @@ public int SelectionCharOffset { } set { if (value > 2000 || value < -2000) - throw new ArgumentOutOfRangeException(nameof(SelectionCharOffset), string.Format(SR.InvalidBoundArgument, "SelectionCharOffset", value, -2000, 2000)); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidBoundArgument, nameof(SelectionCharOffset), value, -2000, 2000)); ForceHandleCreate(); NativeMethods.CHARFORMATA cf = new NativeMethods.CHARFORMATA(); @@ -1232,7 +1232,7 @@ public int SelectionRightIndent { } set { if (value < 0) - throw new ArgumentOutOfRangeException(nameof(SelectionRightIndent), string.Format(SR.InvalidLowBoundArgumentEx, "SelectionRightIndent", value, 0)); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(SelectionRightIndent), value, 0)); ForceHandleCreate(); NativeMethods.PARAFORMAT pf = new NativeMethods.PARAFORMAT(); @@ -1522,12 +1522,17 @@ public float ZoomFactor { else return zoomMultiplier; } - set { - if (zoomMultiplier == value) return; - + set + { if (value <= 0.015625f || value >= 64.0f) - throw new ArgumentOutOfRangeException(nameof(ZoomFactor), string.Format(SR.InvalidExBoundArgument, "ZoomFactor", (value).ToString(CultureInfo.CurrentCulture), (0.015625f).ToString(CultureInfo.CurrentCulture), (64.0f).ToString(CultureInfo.CurrentCulture))); - SendZoomFactor(value); + { + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidExBoundArgument, nameof(ZoomFactor), value, 0.015625f, 64.0f)); + } + + if (value != zoomMultiplier) + { + SendZoomFactor(value); + } } } @@ -1862,9 +1867,9 @@ public int Find(string str, int start, int end, RichTextBoxFinds options) { if (str == null) throw new ArgumentNullException(nameof(str)); if (start < 0 || start > textLen) - throw new ArgumentOutOfRangeException(nameof(start), string.Format(SR.InvalidBoundArgument, "start", start, 0, textLen)); + throw new ArgumentOutOfRangeException(nameof(start), start, string.Format(SR.InvalidBoundArgument, nameof(start), start, 0, textLen)); if (end < -1) - throw new ArgumentOutOfRangeException(nameof(end), string.Format(SR.RichTextFindEndInvalid, end)); + throw new ArgumentOutOfRangeException(nameof(end), end, string.Format(SR.RichTextFindEndInvalid, end)); bool selectWord = true; NativeMethods.FINDTEXT ft = new NativeMethods.FINDTEXT(); @@ -2000,9 +2005,9 @@ public int Find(char[] characterSet, int start, int end) { if (characterSet == null) throw new ArgumentNullException(nameof(characterSet)); if (start < 0 || start > textLength) - throw new ArgumentOutOfRangeException(nameof(start), string.Format(SR.InvalidBoundArgument, "start", start, 0, textLength)); + throw new ArgumentOutOfRangeException(nameof(start), start, string.Format(SR.InvalidBoundArgument, nameof(start), start, 0, textLength)); if (end < start && end != -1) - throw new ArgumentOutOfRangeException(nameof(end), string.Format(SR.InvalidLowBoundArgumentEx, "end", end, "start")); + throw new ArgumentOutOfRangeException(nameof(end), end, string.Format(SR.InvalidLowBoundArgumentEx, nameof(end), end, nameof(start))); // Don't do anything if we get nothing to look for if (characterSet.Length == 0) diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ScrollBar.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ScrollBar.cs index 6a7da6f90b3..df2efb26f8b 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/ScrollBar.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/ScrollBar.cs @@ -320,7 +320,7 @@ public int LargeChange { if (largeChange != value) { if (value < 0) { - throw new ArgumentOutOfRangeException(nameof(LargeChange), string.Format(SR.InvalidLowBoundArgumentEx, "LargeChange", (value).ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(LargeChange), value, 0)); } largeChange = value; @@ -413,7 +413,7 @@ public int SmallChange { if (smallChange != value) { if (value < 0) { - throw new ArgumentOutOfRangeException(nameof(SmallChange), string.Format(SR.InvalidLowBoundArgumentEx, "SmallChange", (value).ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(SmallChange), value, 0)); } smallChange = value; @@ -488,7 +488,7 @@ public int Value { set { if (this.value != value) { if (value < minimum || value > maximum) { - throw new ArgumentOutOfRangeException(nameof(Value), string.Format(SR.InvalidBoundArgument, "Value", (value).ToString(CultureInfo.CurrentCulture), "'minimum'", "'maximum'")); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidBoundArgument, nameof(Value), value, $"'{nameof(Minimum)}'", $"'{nameof(Maximum)}'")); } this.value = value; UpdateScrollInfo(); @@ -770,7 +770,7 @@ private int ReflectPosition(int position) { /// public override string ToString() { string s = base.ToString(); - return s + ", Minimum: " + Minimum.ToString(CultureInfo.CurrentCulture) + ", Maximum: " + Maximum.ToString(CultureInfo.CurrentCulture) + ", Value: " + Value.ToString(CultureInfo.CurrentCulture); + return s + ", Minimum: " + Minimum.ToString(CultureInfo.CurrentCulture) + ", Maximum: " + Maximum.ToString(CultureInfo.CurrentCulture) + ", Value: " + value; } /// diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ScrollProperties.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ScrollProperties.cs index db008a2de1e..dbcc58bd02f 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/ScrollProperties.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/ScrollProperties.cs @@ -110,7 +110,7 @@ public int LargeChange { set { if (largeChange != value ) { if (value < 0) { - throw new ArgumentOutOfRangeException(nameof(LargeChange), string.Format(SR.InvalidLowBoundArgumentEx, "LargeChange", (value).ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(LargeChange), value, 0)); } largeChange = value; largeChangeSetExternally = true; @@ -175,7 +175,7 @@ public int Minimum { } if (minimum != value) { if (value < 0) { - throw new ArgumentOutOfRangeException(nameof(Minimum), string.Format(SR.InvalidLowBoundArgumentEx, "Minimum", (value).ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(Minimum), value, 0)); } if (maximum < value) maximum = value; @@ -231,7 +231,7 @@ public int SmallChange { if (smallChange != value) { if (value < 0) { - throw new ArgumentOutOfRangeException(nameof(SmallChange), string.Format(SR.InvalidLowBoundArgumentEx, "SmallChange", (value).ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(SmallChange), value, 0)); } smallChange = value; @@ -263,7 +263,7 @@ public int Value { set { if (this.value != value) { if (value < minimum || value > maximum) { - throw new ArgumentOutOfRangeException(nameof(Value), string.Format(SR.InvalidBoundArgument, "Value", (value).ToString(CultureInfo.CurrentCulture), "'minimum'", "'maximum'")); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidBoundArgument, nameof(Value), value, $"'{nameof(Minimum)}'", $"'{nameof(Maximum)}'")); } this.value = value; UpdateScrollInfo(); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ScrollableControl.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ScrollableControl.cs index 52a13fc6e62..689949cd63b 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/ScrollableControl.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/ScrollableControl.cs @@ -160,7 +160,7 @@ public Size AutoScrollMargin { set { if (value.Width < 0 || value.Height < 0) { - throw new ArgumentOutOfRangeException(nameof(AutoScrollMargin), string.Format(SR.InvalidArgument, "AutoScrollMargin", value.ToString())); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidArgument, nameof(AutoScrollMargin), value)); } SetAutoScrollMargin(value.Width, value.Height); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/SplitContainer.cs b/src/System.Windows.Forms/src/System/Windows/Forms/SplitContainer.cs index 28a894b5578..fb39e16ea35 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/SplitContainer.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/SplitContainer.cs @@ -772,7 +772,7 @@ public int SplitterDistance if (value != SplitterDistance) { if (value < 0) { - throw new ArgumentOutOfRangeException(nameof(SplitterDistance), string.Format(SR.InvalidLowBoundArgument, "SplitterDistance", (value).ToString(CultureInfo.CurrentCulture), "0")); + throw new ArgumentOutOfRangeException(nameof(SplitterDistance), string.Format(SR.InvalidLowBoundArgument, "SplitterDistance", value, 0)); } @@ -868,7 +868,7 @@ public int SplitterIncrement { set { if (value < 1 ) { - throw new ArgumentOutOfRangeException(nameof(SplitterIncrement), string.Format(SR.InvalidLowBoundArgumentEx, "SplitterIncrement", (value).ToString(CultureInfo.CurrentCulture), "1")); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(SplitterIncrement), value, 1)); } splitterInc = value; @@ -1412,17 +1412,17 @@ protected override void OnRightToLeftChanged(EventArgs e) { /// private void ApplyPanel1MinSize(int value) { if (value < 0) { - throw new ArgumentOutOfRangeException(nameof(Panel1MinSize), string.Format(SR.InvalidLowBoundArgument, "Panel1MinSize", (value).ToString(CultureInfo.CurrentCulture), "0")); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgument, nameof(Panel1MinSize), value)); } if (Orientation== Orientation.Vertical) { if (DesignMode && Width != DefaultSize.Width && value + Panel2MinSize + SplitterWidth > Width) { - throw new ArgumentOutOfRangeException(nameof(Panel1MinSize), string.Format(SR.InvalidArgument, "Panel1MinSize", (value).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidArgument, nameof(Panel1MinSize), value)); } } else if (Orientation == Orientation.Horizontal) { if (DesignMode && Height != DefaultSize.Height && value + Panel2MinSize + SplitterWidth > Height) { - throw new ArgumentOutOfRangeException(nameof(Panel1MinSize), string.Format(SR.InvalidArgument, "Panel1MinSize", (value).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidArgument, nameof(Panel1MinSize), value)); } } @@ -1437,17 +1437,17 @@ private void ApplyPanel1MinSize(int value) { /// private void ApplyPanel2MinSize(int value) { if (value < 0) { - throw new ArgumentOutOfRangeException(nameof(Panel2MinSize), string.Format(SR.InvalidLowBoundArgument, "Panel2MinSize", (value).ToString(CultureInfo.CurrentCulture), "0")); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgument, nameof(Panel2MinSize), value, 0)); } if (Orientation == Orientation.Vertical) { if (DesignMode && Width != DefaultSize.Width && value + Panel1MinSize + SplitterWidth > Width) { - throw new ArgumentOutOfRangeException(nameof(Panel2MinSize), string.Format(SR.InvalidArgument, "Panel2MinSize", (value).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidArgument, nameof(Panel2MinSize), value.ToString())); } } else if (Orientation == Orientation.Horizontal) { if (DesignMode && Height != DefaultSize.Height && value + Panel1MinSize + SplitterWidth > Height) { - throw new ArgumentOutOfRangeException(nameof(Panel2MinSize), string.Format(SR.InvalidArgument, "Panel2MinSize", (value).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidArgument, nameof(Panel2MinSize), value)); } } panel2MinSize = value; @@ -1461,17 +1461,17 @@ private void ApplyPanel2MinSize(int value) { /// private void ApplySplitterWidth(int value) { if (value < 1) { - throw new ArgumentOutOfRangeException(nameof(SplitterWidth), string.Format(SR.InvalidLowBoundArgumentEx, "SplitterWidth", (value).ToString(CultureInfo.CurrentCulture), "1")); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(SplitterWidth), value, 1)); } if (Orientation == Orientation.Vertical) { if (DesignMode && value + Panel1MinSize + Panel2MinSize > Width) { - throw new ArgumentOutOfRangeException(nameof(SplitterWidth), string.Format(SR.InvalidArgument, "SplitterWidth", (value).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidArgument, nameof(SplitterWidth), value)); } } else if (Orientation == Orientation.Horizontal) { if (DesignMode && value + Panel1MinSize + Panel2MinSize > Height) { - throw new ArgumentOutOfRangeException(nameof(SplitterWidth), string.Format(SR.InvalidArgument, "SplitterWidth", (value).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidArgument, nameof(SplitterWidth), value)); } } splitterWidth = value; diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/StatusBar.cs b/src/System.Windows.Forms/src/System/Windows/Forms/StatusBar.cs index 72704d7bd1e..c50075a0185 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/StatusBar.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/StatusBar.cs @@ -1230,7 +1230,7 @@ public virtual StatusBarPanel this[int index] { int length = owner.panels.Count; if (index < 0|| index >= length) - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", index.ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); StatusBarPanel oldPanel = (StatusBarPanel) owner.panels[index]; oldPanel.ParentInternal = null; @@ -1476,7 +1476,7 @@ public virtual void Insert(int index, StatusBarPanel value) { int length = owner.panels.Count; if (index < 0 || index > length) - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", index.ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); value.ParentInternal = owner; switch (value.AutoSize) { @@ -1563,7 +1563,7 @@ void IList.Remove(object value) { public virtual void RemoveAt(int index) { int length = Count; if (index < 0 || index >= length) - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", index.ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); // clear any tooltip // diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/StatusBarPanel.cs b/src/System.Windows.Forms/src/System/Windows/Forms/StatusBarPanel.cs index b95c266ac20..ef8bc7216e8 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/StatusBarPanel.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/StatusBarPanel.cs @@ -255,7 +255,7 @@ public int MinWidth { } set { if (value < 0) { - throw new ArgumentOutOfRangeException(nameof(MinWidth), string.Format(SR.InvalidLowBoundArgumentEx, "MinWidth", value.ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(MinWidth), value, 0)); } if (value != this.minWidth) { diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/TabControl.cs b/src/System.Windows.Forms/src/System/Windows/Forms/TabControl.cs index d76feb86cfd..1e085986459 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/TabControl.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/TabControl.cs @@ -553,7 +553,7 @@ public Size ItemSize { set { if (value.Width < 0 || value.Height < 0) { - throw new ArgumentOutOfRangeException(nameof(ItemSize), string.Format(SR.InvalidArgument, "ItemSize", value.ToString())); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidArgument, nameof(ItemSize), value)); } itemSize = value; ApplyItemSize(); @@ -620,10 +620,10 @@ public bool Multiline { return padding; } set { - //do some validation checking here, against min & max GridSize - // - if ( value.X < 0 || value.Y < 0 ) - throw new ArgumentOutOfRangeException(nameof(Padding), string.Format(SR.InvalidArgument, "Padding", value.ToString())); + if (value.X < 0 || value.Y < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidArgument, nameof(Padding), value)); + } if (padding != value) { padding = value; @@ -712,7 +712,7 @@ public int SelectedIndex { } set { if (value < -1) { - throw new ArgumentOutOfRangeException(nameof(SelectedIndex), string.Format(SR.InvalidLowBoundArgumentEx, "SelectedIndex", value.ToString(CultureInfo.CurrentCulture), (-1).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(SelectedIndex), value, -1)); } if (SelectedIndex != value) { @@ -1170,7 +1170,7 @@ public Control GetControl(int index) { internal TabPage GetTabPage(int index) { if (index < 0 || index >= tabPageCount) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", index.ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } return tabPages[index]; } @@ -1207,7 +1207,7 @@ internal TabPage[] GetTabPages() { /// public Rectangle GetTabRect(int index) { if (index < 0 || (index >= tabPageCount && !tabControlState[TABCONTROLSTATE_getTabRectfromItemSize])) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", index.ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } tabControlState[TABCONTROLSTATE_getTabRectfromItemSize] = false ; NativeMethods.RECT rect = new NativeMethods.RECT(); @@ -1267,7 +1267,7 @@ internal void Insert(int index, TabPage tabPage) { private void InsertItem(int index, TabPage tabPage) { if (index < 0 || ((tabPages != null) && index > tabPageCount)) - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", index.ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); if (tabPage == null) throw new ArgumentNullException(nameof(tabPage)); @@ -1654,7 +1654,7 @@ protected void RemoveAll() { /// internal void RemoveTabPage(int index) { if (index < 0 || index >= tabPageCount) - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", index.ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); tabPageCount--; if (index < tabPageCount) { Array.Copy(tabPages, index + 1, tabPages, index, tabPageCount - index); @@ -1700,7 +1700,7 @@ internal void SetToolTip(ToolTip toolTip, string controlToolTipText) { /// internal void SetTabPage(int index, TabPage tabPage, NativeMethods.TCITEM_T tcitem) { if (index < 0 || index >= tabPageCount) - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", index.ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); if (IsHandleCreated) UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.TCM_SETITEM, index, tcitem); // Make the Updated tab page the currently selected tab page diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/TabPage.cs b/src/System.Windows.Forms/src/System/Windows/Forms/TabPage.cs index ebc5f23c525..ca4db4ba814 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/TabPage.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/TabPage.cs @@ -185,9 +185,11 @@ public int ImageIndex { return ImageIndexer.Index; } set { - if (value < -1) { - throw new ArgumentOutOfRangeException ("ImageIndex", string.Format (SR.InvalidLowBoundArgumentEx, "imageIndex", (value).ToString (CultureInfo.CurrentCulture), (-1).ToString(CultureInfo.CurrentCulture))); + if (value < -1) + { + throw new ArgumentOutOfRangeException(nameof(value), string.Format(SR.InvalidLowBoundArgumentEx, nameof(ImageIndex), value, -1)); } + TabControl parent = ParentInternal as TabControl; if (parent != null) { diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/TableLayoutPanelCellPosition.cs b/src/System.Windows.Forms/src/System/Windows/Forms/TableLayoutPanelCellPosition.cs index 5ea42b9d934..0759cb9ab4e 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/TableLayoutPanelCellPosition.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/TableLayoutPanelCellPosition.cs @@ -18,10 +18,10 @@ public struct TableLayoutPanelCellPosition { public TableLayoutPanelCellPosition(int column, int row) { if (row < -1) { - throw new ArgumentOutOfRangeException(nameof(row), string.Format(SR.InvalidArgument, "row", (row).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(row), row, string.Format(SR.InvalidArgument, nameof(row), row)); } if (column < -1) { - throw new ArgumentOutOfRangeException(nameof(column), string.Format(SR.InvalidArgument, "column", (column).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(column), column, string.Format(SR.InvalidArgument, nameof(column), column)); } this.row = row; this.column = column; diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/TableLayoutSettings.cs b/src/System.Windows.Forms/src/System/Windows/Forms/TableLayoutSettings.cs index e1d3890a686..430fcb9159b 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/TableLayoutSettings.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/TableLayoutSettings.cs @@ -76,7 +76,7 @@ internal TableLayoutPanelCellBorderStyle CellBorderStyle { set { //valid values are 0x0 to 0x6 if (!ClientUtils.IsEnumValid(value, (int)value, (int)TableLayoutPanelCellBorderStyle.None, (int)TableLayoutPanelCellBorderStyle.OutsetPartial)){ - throw new ArgumentException(string.Format(SR.InvalidArgument, "CellBorderStyle", value.ToString())); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidArgument, nameof(CellBorderStyle), value)); } _borderStyle = value; //set the CellBorderWidth according to the current CellBorderStyle. @@ -107,9 +107,11 @@ public int ColumnCount { return containerInfo.MaxColumns; } set { - if (value < 0) { - throw new ArgumentOutOfRangeException(nameof(ColumnCount), value, string.Format (SR.InvalidLowBoundArgumentEx, "ColumnCount", value.ToString (CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(ColumnCount), value, 0)); } + TableLayout.ContainerInfo containerInfo = TableLayout.GetContainerInfo(Owner); containerInfo.MaxColumns = value; LayoutTransaction.DoLayout(Owner, Owner, PropertyNames.Columns); @@ -133,9 +135,11 @@ public int RowCount { return containerInfo.MaxRows; } set { - if (value < 0) { - throw new ArgumentOutOfRangeException(nameof(RowCount), value, string.Format (SR.InvalidLowBoundArgumentEx, "RowCount", value.ToString (CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(RowCount), value, 0)); } + TableLayout.ContainerInfo containerInfo = TableLayout.GetContainerInfo(Owner); containerInfo.MaxRows = value; LayoutTransaction.DoLayout(Owner, Owner, PropertyNames.Rows); @@ -193,7 +197,7 @@ public TableLayoutPanelGrowStyle GrowStyle { set { //valid values are 0x0 to 0x2 if (!ClientUtils.IsEnumValid(value, (int)value, (int)TableLayoutPanelGrowStyle.FixedSize, (int)TableLayoutPanelGrowStyle.AddColumns)){ - throw new ArgumentException(string.Format(SR.InvalidArgument, "GrowStyle", value.ToString())); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidArgument, nameof(GrowStyle), value)); } TableLayout.ContainerInfo containerInfo = TableLayout.GetContainerInfo(Owner); @@ -255,7 +259,7 @@ public void SetColumnSpan(object control, int value) } if (value < 1) { - throw new ArgumentOutOfRangeException(nameof(value), string.Format(SR.InvalidArgument, "ColumnSpan", value)); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidArgument, nameof(value), value)); } if (IsStub) @@ -302,7 +306,7 @@ public void SetRowSpan(object control, int value) } if (value < 1) { - throw new ArgumentOutOfRangeException(nameof(value), string.Format(SR.InvalidArgument, "RowSpan", value)); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidArgument, nameof(value), value)); } if (IsStub) @@ -360,7 +364,7 @@ public void SetRow(object control, int row) } if (row < -1) { - throw new ArgumentOutOfRangeException(nameof(row), string.Format(SR.InvalidArgument, "Row", row)); + throw new ArgumentOutOfRangeException(nameof(row), row, string.Format(SR.InvalidArgument, nameof(row), row)); } SetCellPosition(control, row, -1, rowSpecified: true, colSpecified: false); @@ -436,7 +440,7 @@ public void SetColumn(object control, int column) } if (column < -1) { - throw new ArgumentException(string.Format(SR.InvalidArgument, "Column", column)); + throw new ArgumentOutOfRangeException(nameof(column), column, string.Format(SR.InvalidArgument, nameof(column), column)); } if (IsStub) diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/TableLayoutStyle.cs b/src/System.Windows.Forms/src/System/Windows/Forms/TableLayoutStyle.cs index 32b34db3133..ec5a86c6be8 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/TableLayoutStyle.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/TableLayoutStyle.cs @@ -43,7 +43,7 @@ internal float Size { get { return _size; } set { if (value < 0) { - throw new ArgumentOutOfRangeException(nameof(Size), string.Format(SR.InvalidLowBoundArgumentEx, "Size", value.ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(Size), value, 0)); } if (_size != value) { _size = value; diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/TextBoxBase.cs b/src/System.Windows.Forms/src/System/Windows/Forms/TextBoxBase.cs index c55459904f9..6091f9b8a56 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/TextBoxBase.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/TextBoxBase.cs @@ -732,7 +732,7 @@ public virtual int MaxLength { } set { if (value < 0) { - throw new ArgumentOutOfRangeException(nameof(MaxLength), string.Format(SR.InvalidLowBoundArgumentEx, "MaxLength", (value).ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(MaxLength), value, 0)); } if (maxLength != value) { @@ -1127,7 +1127,7 @@ public virtual int SelectionLength { set { if (value < 0){ - throw new ArgumentOutOfRangeException(nameof(SelectionLength), string.Format(SR.InvalidArgument, "SelectionLength", value.ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidArgument, nameof(SelectionLength), value)); } int selStart, selLength; @@ -1163,7 +1163,7 @@ public int SelectionStart { } set { if (value < 0){ - throw new ArgumentOutOfRangeException(nameof(SelectionStart), string.Format(SR.InvalidArgument, "SelectionStart", value.ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidArgument, nameof(SelectionStart), value)); } Select(value, SelectionLength); } @@ -1708,7 +1708,7 @@ public virtual Point GetPositionFromCharIndex(int index) { /// public int GetFirstCharIndexFromLine(int lineNumber) { if (lineNumber < 0) { - throw new ArgumentOutOfRangeException(nameof(lineNumber), string.Format(SR.InvalidArgument, "lineNumber", lineNumber.ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(lineNumber), lineNumber, string.Format(SR.InvalidArgument, nameof(lineNumber), lineNumber)); } return unchecked( (int) (long)SendMessage(NativeMethods.EM_LINEINDEX, lineNumber, 0)); } @@ -1824,7 +1824,7 @@ public void DeselectAll() { /// public void Select(int start, int length) { if (start < 0){ - throw new ArgumentOutOfRangeException(nameof(start), string.Format(SR.InvalidArgument, "start", start.ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(start), start, string.Format(SR.InvalidArgument, nameof(start), start)); } int textLen = TextLength; diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Timer.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Timer.cs index 39f35ae804c..00a17afc2e7 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Timer.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Timer.cs @@ -209,7 +209,7 @@ public int Interval { set { lock(syncObj) { if (value < 1) - throw new ArgumentOutOfRangeException(nameof(Interval), string.Format(SR.TimerInvalidInterval, value, (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(Interval), string.Format(SR.TimerInvalidInterval, value, 0)); if (interval != value) { interval = value; diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ToolBar.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ToolBar.cs index ae00408a38b..1bbf16ac01f 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/ToolBar.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/ToolBar.cs @@ -384,7 +384,7 @@ public Size ButtonSize { set { if (value.Width < 0 || value.Height < 0) - throw new ArgumentOutOfRangeException(nameof(ButtonSize), string.Format(SR.InvalidArgument, "ButtonSize", value.ToString())); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidArgument, nameof(ButtonSize), value)); if (buttonSize != value) { buttonSize = value; @@ -1175,7 +1175,7 @@ private void InsertButton(int index, ToolBarButton value) { if (value == null) throw new ArgumentNullException(nameof(value)); if (index < 0 || ((buttons != null) && (index > buttonCount))) - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", index.ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); // insert the button into our local array, and then into the // real windows ToolBar control @@ -1752,7 +1752,7 @@ public ToolBarButtonCollection(ToolBar owner) { public virtual ToolBarButton this[int index] { get { if (index < 0 || ((owner.buttons != null) && (index >= owner.buttonCount))) - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", index.ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); return owner.buttons[index]; } set { @@ -1760,7 +1760,7 @@ public virtual ToolBarButton this[int index] { // Sanity check parameters // if (index < 0 || ((owner.buttons != null) && index >= owner.buttonCount)) { - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", index.ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); } if (value == null) { throw new ArgumentNullException(nameof(value)); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ToolBarButton.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ToolBarButton.cs index c5f9c7ac551..091b8ae960d 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/ToolBarButton.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/ToolBarButton.cs @@ -191,7 +191,7 @@ public int ImageIndex { set { if (ImageIndexer.Index != value) { if (value < -1) - throw new ArgumentOutOfRangeException(nameof(ImageIndex), string.Format(SR.InvalidLowBoundArgumentEx, "ImageIndex", (value).ToString(CultureInfo.CurrentCulture), -1)); + throw new ArgumentOutOfRangeException(nameof(ImageIndex), string.Format(SR.InvalidLowBoundArgumentEx, nameof(ImageIndex), value, -1)); ImageIndexer.Index = value; UpdateButton(false); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ToolStripItem.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ToolStripItem.cs index a5386ada1a1..4567aeea5b3 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/ToolStripItem.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/ToolStripItem.cs @@ -1270,7 +1270,7 @@ public int ImageIndex { } set { if (value < -1) { - throw new ArgumentOutOfRangeException(nameof(value), string.Format(SR.InvalidLowBoundArgumentEx, nameof(ImageIndex), value.ToString(CultureInfo.CurrentCulture), (-1).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), string.Format(SR.InvalidLowBoundArgumentEx, nameof(ImageIndex), value, -1)); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ToolStripSplitButton.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ToolStripSplitButton.cs index f029bd6d632..4cd007fb7f6 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/ToolStripSplitButton.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/ToolStripSplitButton.cs @@ -254,7 +254,7 @@ public int DropDownButtonWidth { set { if (value < 0) { // throw if less than 0. - throw new ArgumentOutOfRangeException(nameof(DropDownButtonWidth), string.Format(SR.InvalidLowBoundArgumentEx, "DropDownButtonWidth", value.ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(DropDownButtonWidth), value, 0)); } if (dropDownButtonWidth != value) { diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ToolTip.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ToolTip.cs index cfaba468fea..9a071d8af37 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/ToolTip.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/ToolTip.cs @@ -165,7 +165,7 @@ public int AutomaticDelay { set { if (value < 0) { - throw new ArgumentOutOfRangeException(nameof(AutomaticDelay), string.Format(SR.InvalidLowBoundArgumentEx, "AutomaticDelay", (value).ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(AutomaticDelay), value, 0)); } SetDelayTime(NativeMethods.TTDT_AUTOMATIC, value); } @@ -193,7 +193,7 @@ public int AutoPopDelay { set { if (value < 0) { - throw new ArgumentOutOfRangeException(nameof(AutoPopDelay), string.Format(SR.InvalidLowBoundArgumentEx, "AutoPopDelay", (value).ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(AutoPopDelay), value, 0)); } SetDelayTime(NativeMethods.TTDT_AUTOPOP, value); } @@ -363,7 +363,7 @@ public int InitialDelay { set { if (value < 0) { - throw new ArgumentOutOfRangeException(nameof(InitialDelay), string.Format(SR.InvalidLowBoundArgumentEx, "InitialDelay", (value).ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(InitialDelay), value, 0)); } SetDelayTime(NativeMethods.TTDT_INITIAL, value); } @@ -409,7 +409,7 @@ public int ReshowDelay { } set { if (value < 0) { - throw new ArgumentOutOfRangeException(nameof(ReshowDelay), string.Format(SR.InvalidLowBoundArgumentEx, "ReshowDelay", (value).ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(ReshowDelay), value, 0)); } SetDelayTime(NativeMethods.TTDT_RESHOW, value); } @@ -1606,7 +1606,7 @@ public void Show(string text, IWin32Window window) { /// public void Show(string text, IWin32Window window, int duration) { if (duration < 0) { - throw new ArgumentOutOfRangeException(nameof(duration), string.Format(SR.InvalidLowBoundArgumentEx, "duration", (duration).ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(duration), duration, string.Format(SR.InvalidLowBoundArgumentEx, nameof(duration), duration, 0)); } if (IsWindowActive(window)) { @@ -1648,7 +1648,7 @@ public void Show(string text, IWin32Window window, Point point, int duration) { throw new ArgumentNullException(nameof(window)); } if (duration < 0) { - throw new ArgumentOutOfRangeException(nameof(duration), string.Format(SR.InvalidLowBoundArgumentEx, "duration", (duration).ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(duration), duration, string.Format(SR.InvalidLowBoundArgumentEx, nameof(duration), duration, 0)); } if (IsWindowActive(window)) { @@ -1697,7 +1697,7 @@ public void Show(string text, IWin32Window window, int x, int y, int duration) { throw new ArgumentNullException(nameof(window)); } if (duration < 0) { - throw new ArgumentOutOfRangeException(nameof(duration), string.Format(SR.InvalidLowBoundArgumentEx, "duration", (duration).ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(duration), duration, string.Format(SR.InvalidLowBoundArgumentEx, nameof(duration), duration, 0)); } if (IsWindowActive(window)) { @@ -1716,7 +1716,7 @@ internal void ShowKeyboardToolTip(string text, IKeyboardToolTip tool, int durati throw new ArgumentNullException(nameof(tool)); } if (duration < 0) { - throw new ArgumentOutOfRangeException(nameof(duration), string.Format(SR.InvalidLowBoundArgumentEx, nameof(duration), (duration).ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(duration), string.Format(SR.InvalidLowBoundArgumentEx, nameof(duration), (duration).ToString(CultureInfo.CurrentCulture), 0)); } Rectangle toolRectangle = tool.GetNativeScreenRectangle(); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/TrackBar.cs b/src/System.Windows.Forms/src/System/Windows/Forms/TrackBar.cs index 1f414bed8b0..cf858bb8aac 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/TrackBar.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/TrackBar.cs @@ -661,7 +661,10 @@ public int Value { set { if (this.value != value) { if (!initializing && ((value < minimum) || (value > maximum))) - throw new ArgumentOutOfRangeException(nameof(Value), string.Format(SR.InvalidBoundArgument, "Value", (value).ToString(CultureInfo.CurrentCulture), "'Minimum'", "'Maximum'")); + { + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidBoundArgument, nameof(Value), value, $"'{nameof(Minimum)}'", $"'${nameof(Maximum)}'")); + } + this.value = value; SetTrackBarPosition(); OnValueChanged(EventArgs.Empty); @@ -1120,7 +1123,7 @@ private void SetTrackBarPosition() { public override string ToString() { string s = base.ToString(); - return s + ", Minimum: " + Minimum.ToString(CultureInfo.CurrentCulture) + ", Maximum: " + Maximum.ToString(CultureInfo.CurrentCulture) + ", Value: " + Value.ToString(CultureInfo.CurrentCulture); + return s + ", Minimum: " + Minimum.ToString(CultureInfo.CurrentCulture) + ", Maximum: " + Maximum.ToString(CultureInfo.CurrentCulture) + ", Value: " + value; } /// diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/TreeNode.cs b/src/System.Windows.Forms/src/System/Windows/Forms/TreeNode.cs index fa7bf52d2dd..615f3246641 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/TreeNode.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/TreeNode.cs @@ -959,7 +959,7 @@ public int StateImageIndex { } set { if (value < -1 || value > ALLOWEDIMAGES) { - throw new ArgumentOutOfRangeException(nameof(StateImageIndex), string.Format(SR.InvalidArgument, "StateImageIndex", (value).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidArgument, nameof(StateImageIndex), value)); } StateImageIndexer.Index = value; if (treeView != null && !treeView.CheckBoxes) @@ -1398,7 +1398,7 @@ protected virtual void Deserialize(SerializationInfo serializationInfo, Streamin case "IsChecked": CheckedStateInternal = serializationInfo.GetBoolean(entry.Name); break; - case "ImageIndex": + case nameof(ImageIndex): imageIndex = serializationInfo.GetInt32(entry.Name); break; case "SelectedImageIndex": @@ -1849,7 +1849,7 @@ protected virtual void Serialize(SerializationInfo si, StreamingContext context) si.AddValue("ToolTipText", toolTipText); si.AddValue("Name", Name); si.AddValue("IsChecked", treeNodeState[TREENODESTATE_isChecked]); - si.AddValue("ImageIndex", ImageIndexer.Index); + si.AddValue(nameof(ImageIndex), ImageIndexer.Index); si.AddValue("ImageKey", ImageIndexer.Key); si.AddValue("SelectedImageIndex", SelectedImageIndexer.Index); si.AddValue("SelectedImageKey", SelectedImageIndexer.Key); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/TreeNodeCollection.cs b/src/System.Windows.Forms/src/System/Windows/Forms/TreeNodeCollection.cs index c740d0c4f05..b787896a2d9 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/TreeNodeCollection.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/TreeNodeCollection.cs @@ -59,7 +59,7 @@ public virtual TreeNode this[int index] { } set { if (index < 0 || index >= owner.childCount) - throw new ArgumentOutOfRangeException(nameof(index), string.Format(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); value.parent = owner; value.index = index; owner.children[index] = value; diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/TreeView.cs b/src/System.Windows.Forms/src/System/Windows/Forms/TreeView.cs index 91deb7c60e0..1cb4c8dcd96 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/TreeView.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/TreeView.cs @@ -562,7 +562,7 @@ public int ImageIndex { } if (value < 0) { - throw new ArgumentOutOfRangeException(nameof(ImageIndex), string.Format(SR.InvalidLowBoundArgumentEx, "ImageIndex", value.ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(ImageIndex), string.Format(SR.InvalidLowBoundArgumentEx, nameof(ImageIndex), value, 0)); } if (ImageIndexer.Index != value) { @@ -749,10 +749,10 @@ public int Indent { set { if (indent != value) { if (value < 0) { - throw new ArgumentOutOfRangeException(nameof(Indent), string.Format(SR.InvalidLowBoundArgumentEx, "Indent", (value).ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(Indent), value, 0)); } if (value > MaxIndent) { - throw new ArgumentOutOfRangeException(nameof(Indent), string.Format(SR.InvalidHighBoundArgumentEx, "Indent", (value).ToString(CultureInfo.CurrentCulture), (MaxIndent).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidHighBoundArgumentEx, nameof(Indent), value, MaxIndent)); } indent = value; if (IsHandleCreated) { @@ -791,11 +791,12 @@ public int ItemHeight { set { if (itemHeight != value) { if (value < 1) { - throw new ArgumentOutOfRangeException(nameof(ItemHeight), string.Format(SR.InvalidLowBoundArgumentEx, "ItemHeight", (value).ToString(CultureInfo.CurrentCulture), (1).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(ItemHeight), value, 1)); } if (value >= short.MaxValue) { - throw new ArgumentOutOfRangeException(nameof(ItemHeight), string.Format(SR.InvalidHighBoundArgument, "ItemHeight", (value).ToString(CultureInfo.CurrentCulture), short.MaxValue.ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidHighBoundArgument, nameof(ItemHeight), value, short.MaxValue)); } + itemHeight = value; if (IsHandleCreated) { if (itemHeight % 2 != 0) { @@ -1043,7 +1044,7 @@ public int SelectedImageIndex { } if (value < 0) { - throw new ArgumentOutOfRangeException(nameof(SelectedImageIndex), string.Format(SR.InvalidLowBoundArgumentEx, "SelectedImageIndex", value.ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(SelectedImageIndex), value, 0)); } if (SelectedImageIndexer.Index != value) { SelectedImageIndexer.Index = value; diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/VisualStyles/VisualStyleRenderer.cs b/src/System.Windows.Forms/src/System/Windows/Forms/VisualStyles/VisualStyleRenderer.cs index db3668c3d3f..0491fe4d4df 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/VisualStyles/VisualStyleRenderer.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/VisualStyles/VisualStyleRenderer.cs @@ -403,7 +403,7 @@ public void DrawImage(Graphics g, Rectangle bounds, ImageList imageList, int ima } if (imageIndex < 0 || imageIndex >= imageList.Images.Count) { - throw new ArgumentOutOfRangeException(nameof(imageIndex), string.Format(SR.InvalidArgument, "imageIndex", imageIndex.ToString(CultureInfo.CurrentCulture))); + throw new ArgumentOutOfRangeException(nameof(imageIndex), imageIndex, string.Format(SR.InvalidArgument, nameof(imageIndex), imageIndex)); } if (bounds.Width < 0 || bounds.Height < 0) { diff --git a/src/System.Windows.Forms/tests/UnitTests/DomainUpDownTests.cs b/src/System.Windows.Forms/tests/UnitTests/DomainUpDownTests.cs index 3ed3a1d61f8..cf958622291 100644 --- a/src/System.Windows.Forms/tests/UnitTests/DomainUpDownTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/DomainUpDownTests.cs @@ -35,12 +35,8 @@ public void DomainUpDown_SelectedIndexGetSet(int indexToSet, int indexAfterSet, [Fact] public void DomainUpDown_SelectedIndex_ArgumentOutOfRangeException() { - var underTest = GetNewDomainUpDown(); - var index = 3100; - var paramName = "SelectedIndex"; - var ex = Assert.Throws(() => underTest.SelectedIndex = index); - Assert.Equal(paramName, ex.ParamName); - Assert.Contains($"Value of '{index}' is not valid for '{paramName}'.{Environment.NewLine}Parameter name: {paramName}", ex.Message); + var upDown = GetNewDomainUpDown(); + Assert.Throws(() => upDown.SelectedIndex = 3100); } [Fact] diff --git a/src/System.Windows.Forms/tests/UnitTests/MenuItemTests.cs b/src/System.Windows.Forms/tests/UnitTests/MenuItemTests.cs index 3cff9f5bbed..1c2f46ec26f 100644 --- a/src/System.Windows.Forms/tests/UnitTests/MenuItemTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/MenuItemTests.cs @@ -481,7 +481,7 @@ public void MenuItem_Index_SetInvalid_ThrowsArgumentOutOfRangeException(int valu { var menuItem = new MenuItem(); var menu = new SubMenu(new MenuItem[] { menuItem }); - Assert.Throws("Index", () => menuItem.Index = value); + Assert.Throws("value", () => menuItem.Index = value); } [Theory] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ColumnHeaderTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ColumnHeaderTests.cs index f736d752bdd..1c2d671a0f0 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ColumnHeaderTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ColumnHeaderTests.cs @@ -294,7 +294,7 @@ public void ColumnHeader_ImageIndex_SetWithListViewWithHandle_GetReturnsExpected public void ColumnHeader_ImageIndex_SetInvalid_ThrowsArgumentOutOfRangeException(int value) { var header = new ColumnHeader(); - Assert.Throws("ImageIndex", () => header.ImageIndex = value); + Assert.Throws("value", () => header.ImageIndex = value); } [Theory] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ColumnStyleTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ColumnStyleTests.cs index b37eefc6bd5..57f07b8db4b 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ColumnStyleTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ColumnStyleTests.cs @@ -44,7 +44,7 @@ public void ColumnStyle_Ctor_SizeType_Float(SizeType sizeType, float width) [Fact] public void ColumnStyle_Ctor_NegativeWidth_ThrowsArgumentOutOfRangeException() { - Assert.Throws("Size", () => new ColumnStyle(SizeType.AutoSize, -1)); + Assert.Throws("value", () => new ColumnStyle(SizeType.AutoSize, -1)); } [Theory] @@ -74,7 +74,7 @@ public void ColumnStyle_Width_SetOwned_GetReturnsExpected(float value) public void ColumnStyle_Width_SetNegative_ThrowsArgumentOutOfRangeException() { var style = new ColumnStyle(); - Assert.Throws("Size", () => style.Width = -1); + Assert.Throws("value", () => style.Width = -1); } } } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewRowHeightInfoNeededEventArgsTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewRowHeightInfoNeededEventArgsTests.cs index a0cdc475361..570f2618fd7 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewRowHeightInfoNeededEventArgsTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewRowHeightInfoNeededEventArgsTests.cs @@ -50,7 +50,7 @@ public void Height_SetInvalid_ThrowsArgumentOutOfRangeException(int value) DataGridViewRowHeightInfoNeededEventHandler handler = (sender, e) => { callCount++; - Assert.Throws("Height", () => e.Height = value); + Assert.Throws("value", () => e.Height = value); }; dataGridView.RowHeightInfoNeeded += handler; @@ -106,7 +106,7 @@ public void MinimumHeight_SetInvalid_ThrowsArgumentOutOfRangeException(int value DataGridViewRowHeightInfoNeededEventHandler handler = (sender, e) => { callCount++; - Assert.Throws("MinimumHeight", () => e.MinimumHeight = value); + Assert.Throws("value", () => e.MinimumHeight = value); }; dataGridView.RowHeightInfoNeeded += handler; diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewRowTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewRowTests.cs index 1e875a74d58..356d0994fd5 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewRowTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewRowTests.cs @@ -405,7 +405,7 @@ public void DataGridViewRow_DefaultHeaderCellType_SetWithNonNullOldValue_GetRetu public void DataGridViewRow_DefaultHeaderCellType_SetInvalidWithNullOldValue_GetReturnsExpected(Type value) { var row = new SubDataGridViewRow(); - Assert.Throws(null, () => row.DefaultHeaderCellType = value); + Assert.Throws("value", () => row.DefaultHeaderCellType = value); } [Theory] @@ -417,7 +417,7 @@ public void DataGridViewRow_DefaultHeaderCellType_SetInvalidWithNonNullOldValue_ { DefaultHeaderCellType = typeof(DataGridViewRowHeaderCell) }; - Assert.Throws(null, () => row.DefaultHeaderCellType = value); + Assert.Throws("value", () => row.DefaultHeaderCellType = value); } public static IEnumerable Displayed_Get_TestData() @@ -528,7 +528,7 @@ public void DataGridViewRow_DividerHeight_SetWithDataGridView_CallsRowDividerHei public void DataGridViewRow_DividerHeight_SetInvalid_ThrowsArgumentOutOfRangeException(int value) { var row = new DataGridViewRow(); - Assert.Throws("DividerHeight", () => row.DividerHeight = value); + Assert.Throws("value", () => row.DividerHeight = value); } [Theory] @@ -1052,7 +1052,7 @@ public void DataGridViewRow_Height_SetWithDataGridView_CallsRowHeightChanged() public void DataGridViewRow_Height_SetInvalid_ThrowsArgumentOutOfRangeException(int value) { var row = new DataGridViewRow(); - Assert.Throws("Height", () => row.Height = value); + Assert.Throws("value", () => row.Height = value); } [Theory] @@ -1353,14 +1353,14 @@ public void DataGridViewRow_MinimumHeight_SetWithDataGridView_CallsRowMinimumHei } [Theory] - [InlineData(-1, "MinimumHeight")] - [InlineData(0, "MinimumHeight")] - [InlineData(1, "MinimumHeight")] - [InlineData(65537, "Height")] - public void DataGridViewRow_MinimumHeight_SetInvalid_ThrowsArgumentOutOfRangeException(int value, string paramName) + [InlineData(-1)] + [InlineData(0)] + [InlineData(1)] + [InlineData(65537)] + public void DataGridViewRow_MinimumHeight_SetInvalid_ThrowsArgumentOutOfRangeException(int value) { var row = new DataGridViewRow(); - Assert.Throws(paramName, () => row.MinimumHeight = value); + Assert.Throws("value", () => row.MinimumHeight = value); Assert.Equal(3, row.MinimumHeight); Assert.Equal(Control.DefaultFont.Height + 9, row.Height); } @@ -2889,7 +2889,7 @@ public void DataGridViewRow_GetState_Invoke_ReturnsExpected(DataGridViewRow row, public void DataGridViewRow_GetState_NoDataGridViewInvalidRowIndex_ThrowsArgumentException(int rowIndex) { var row = new DataGridViewRow(); - Assert.Throws(null, () => row.GetState(rowIndex)); + Assert.Throws("rowIndex", () => row.GetState(rowIndex)); } [Theory] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Layout/TableLayoutSettingsTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Layout/TableLayoutSettingsTests.cs index b881da8b5e8..ee1fb18c740 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Layout/TableLayoutSettingsTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Layout/TableLayoutSettingsTests.cs @@ -95,7 +95,7 @@ public void TableLayoutSettings_ColumnCount_SetNegative_ThrowsArgumentOutOfRange { var toolStrip = new ToolStrip { LayoutStyle = ToolStripLayoutStyle.Table }; TableLayoutSettings settings = Assert.IsType(toolStrip.LayoutSettings); - Assert.Throws("ColumnCount", () => settings.ColumnCount = -1); + Assert.Throws("value", () => settings.ColumnCount = -1); } [Theory] @@ -114,7 +114,7 @@ public void TableLayoutSettings_RowCount_SetNegative_ThrowsArgumentOutOfRangeExc { var toolStrip = new ToolStrip { LayoutStyle = ToolStripLayoutStyle.Table }; TableLayoutSettings settings = Assert.IsType(toolStrip.LayoutSettings); - Assert.Throws("RowCount", () => settings.RowCount = -1); + Assert.Throws("value", () => settings.RowCount = -1); } [Theory] @@ -132,11 +132,11 @@ public void TableLayoutSettings_GrowStyle_Set_GetReturnsExpected(TableLayoutPane [Theory] [InlineData((TableLayoutPanelGrowStyle)(TableLayoutPanelGrowStyle.FixedSize - 1))] [InlineData((TableLayoutPanelGrowStyle)(TableLayoutPanelGrowStyle.AddColumns + 1))] - public void TableLayoutSettings_GrowStyle_SetNegative_ThrowsArgumentException(TableLayoutPanelGrowStyle value) + public void TableLayoutSettings_GrowStyle_SetNegative_ThrowsArgumentOutOfRangeException(TableLayoutPanelGrowStyle value) { var toolStrip = new ToolStrip { LayoutStyle = ToolStripLayoutStyle.Table }; TableLayoutSettings settings = Assert.IsType(toolStrip.LayoutSettings); - Assert.Throws(null, () => settings.GrowStyle = value); + Assert.Throws("value", () => settings.GrowStyle = value); } [Theory] @@ -651,9 +651,9 @@ public void TableLayoutSettings_SetColumn_InvalidControlStub_ThrowsNotSupportedE [Theory] [MemberData(nameof(EmptySettings_TestData))] - public void TableLayoutSettings_SetColumn_InvalidColumn_ThrowsArgumentException(TableLayoutSettings settings) + public void TableLayoutSettings_SetColumn_InvalidColumn_ThrowsArgumentOutOfRangeException(TableLayoutSettings settings) { - Assert.Throws(null, () => settings.SetColumn("control", -2)); + Assert.Throws("column", () => settings.SetColumn("control", -2)); } [Fact] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RowStyleTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RowStyleTests.cs index 5407e106d34..3f00e47ea96 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RowStyleTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RowStyleTests.cs @@ -44,7 +44,7 @@ public void RowStyle_Ctor_SizeType_Float(SizeType sizeType, float height) [Fact] public void RowStyle_Ctor_NegativeHeight_ThrowsArgumentOutOfRangeException() { - Assert.Throws("Size", () => new RowStyle(SizeType.AutoSize, -1)); + Assert.Throws("value", () => new RowStyle(SizeType.AutoSize, -1)); } [Theory] @@ -74,7 +74,7 @@ public void RowStyle_Height_SetOwned_GetReturnsExpected(float value) public void RowStyle_Height_SetNegative_ThrowsArgumentOutOfRangeException() { var style = new RowStyle(); - Assert.Throws("Size", () => style.Height = -1); + Assert.Throws("value", () => style.Height = -1); } } } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ScrollPropertiesTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ScrollPropertiesTests.cs index 818ea6cdc4f..53488c8f470 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ScrollPropertiesTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ScrollPropertiesTests.cs @@ -101,7 +101,7 @@ public void ScrollProperties_LargeChange_SetNegative_ThrowsArgumentOutOfRangeExc { var control = new ScrollableControl(); var properties = new SubScrollProperties(control); - Assert.Throws("LargeChange", () => properties.LargeChange = -1); + Assert.Throws("value", () => properties.LargeChange = -1); Assert.Equal(10, properties.LargeChange); } @@ -150,7 +150,7 @@ public void ScrollProperties_SmallChange_SetNegative_ThrowsArgumentOutOfRangeExc { var control = new ScrollableControl(); var properties = new SubScrollProperties(control); - Assert.Throws("SmallChange", () => properties.SmallChange = -1); + Assert.Throws("value", () => properties.SmallChange = -1); Assert.Equal(1, properties.SmallChange); } @@ -301,7 +301,7 @@ public void ScrollProperties_Minimum_SetNegative_ThrowsArgumentOutOfRangeExcepti { var control = new ScrollableControl(); var properties = new SubScrollProperties(control); - Assert.Throws("Minimum", () => properties.Minimum = -1); + Assert.Throws("value", () => properties.Minimum = -1); Assert.Equal(0, properties.Minimum); } @@ -359,7 +359,7 @@ public void ScrollProperties_Value_SetOutOfRange_ThrowsArgumentOutOfRangeExcepti { var control = new ScrollableControl(); var properties = new SubScrollProperties(control); - Assert.Throws("Value", () => properties.Value = value); + Assert.Throws("value", () => properties.Value = value); Assert.Equal(0, properties.Value); } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ScrollableControlTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ScrollableControlTests.cs index 3d8c2653e02..52749a7db34 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ScrollableControlTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ScrollableControlTests.cs @@ -67,7 +67,7 @@ public static IEnumerable AutoScrollMargin_Invalid_TestData() public void ScrollableControl_AutoScrollMargin_SetInvalid_ThrowsArgumentOutOfRangeException(Size value) { var control = new ScrollableControl(); - Assert.Throws("AutoScrollMargin", () => control.AutoScrollMargin = value); + Assert.Throws("value", () => control.AutoScrollMargin = value); } public static IEnumerable SetAutoScrollMargin_TestData() diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TableLayoutControlCollectionTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TableLayoutControlCollectionTests.cs index 1d545782d7a..8b722e10314 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TableLayoutControlCollectionTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TableLayoutControlCollectionTests.cs @@ -40,12 +40,12 @@ public void TableLayoutControlCollection_Add_ValidControl_Success(int column, in } [Fact] - public void TableLayoutControlCollection_Add_NegativeColumn_ThrowsArgumentException() + public void TableLayoutControlCollection_Add_NegativeColumn_ThrowsArgumentOutOfRangeException() { var container = new TableLayoutPanel(); var collection = new TableLayoutControlCollection(container); var control = new Control(); - Assert.Throws(null, () => collection.Add(control, -2, 2)); + Assert.Throws("column", () => collection.Add(control, -2, 2)); Assert.Equal(control, Assert.Single(collection)); Assert.Equal(-1, container.GetColumn(control)); Assert.Equal(-1, container.GetRow(control)); diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TableLayoutPanelTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TableLayoutPanelTests.cs index 68644a0b376..bd571705efe 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TableLayoutPanelTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TableLayoutPanelTests.cs @@ -62,10 +62,10 @@ public void TableLayoutPanel_CellBorderStyle_Set_GetReturnsExpected(TableLayoutP [Theory] [CommonMemberData(nameof(CommonTestHelper.GetEnumTypeTheoryDataInvalid), typeof(TableLayoutPanelCellBorderStyle))] - public void TableLayoutPanel_CellBorderStyle_SetInvalid_ThrowsArgumentException(TableLayoutPanelCellBorderStyle value) + public void TableLayoutPanel_CellBorderStyle_SetInvalid_ThrowsArgumentOutOfRangeException(TableLayoutPanelCellBorderStyle value) { var panel = new TableLayoutPanel(); - Assert.Throws(null, () => panel.CellBorderStyle = value); + Assert.Throws("value", () => panel.CellBorderStyle = value); } [Fact] @@ -183,7 +183,7 @@ public void TableLayoutPanel_ColumnCount_Set_GetReturnsExpected(int value) public void TableLayoutPanel_ColumnCount_SetNegative_ThrowsArgumentOutOfRangeException() { var panel = new TableLayoutPanel(); - Assert.Throws("ColumnCount", () => panel.ColumnCount = -1); + Assert.Throws("value", () => panel.ColumnCount = -1); } [Theory] @@ -202,7 +202,7 @@ public void TableLayoutPanel_RowCount_Set_GetReturnsExpected(int value) public void TableLayoutPanel_RowCount_SetNegative_ThrowsArgumentOutOfRangeException() { var panel = new TableLayoutPanel(); - Assert.Throws("RowCount", () => panel.RowCount = -1); + Assert.Throws("value", () => panel.RowCount = -1); } [Theory] @@ -221,10 +221,10 @@ public void TableLayoutPanel_GrowStyle_Set_GetReturnsExpected(TableLayoutPanelGr [Theory] [InlineData((TableLayoutPanelGrowStyle)(TableLayoutPanelGrowStyle.FixedSize - 1))] [InlineData((TableLayoutPanelGrowStyle)(TableLayoutPanelGrowStyle.AddColumns + 1))] - public void TableLayoutPanel_GrowStyle_SetNegative_ThrowsArgumentException(TableLayoutPanelGrowStyle value) + public void TableLayoutPanel_GrowStyle_SetNegative_ThrowsArgumentOutOfRangeException(TableLayoutPanelGrowStyle value) { var panel = new TableLayoutPanel(); - Assert.Throws(null, () => panel.GrowStyle = value); + Assert.Throws("value", () => panel.GrowStyle = value); } [Fact] @@ -513,10 +513,10 @@ public void TableLayoutPanel_SetColumn_NullControl_ThrowsArgumentNullException(i } [Fact] - public void TableLayoutPanel_SetColumn_InvalidColumn_ThrowsArgumentException() + public void TableLayoutPanel_SetColumn_InvalidColumn_ThrowsArgumentOutOfRangeException() { var panel = new TableLayoutPanel(); - Assert.Throws(null, () => panel.SetColumn(new Control(), -2)); + Assert.Throws("column", () => panel.SetColumn(new Control(), -2)); } [Theory] @@ -599,19 +599,19 @@ public void TableLayoutPanel_GetControlFromPosition_NoSuchControl_ReturnsExpecte [Theory] [InlineData(-2)] [InlineData(-1)] - public void TableLayoutPanel_GetControlFromPosition_NegativeColumn_ThrowsArgumentException(int column) + public void TableLayoutPanel_GetControlFromPosition_NegativeColumn_ThrowsArgumentOutOfRangeException(int column) { var panel = new TableLayoutPanel(); - Assert.Throws(null, () => panel.GetControlFromPosition(column, 0)); + Assert.Throws("column", () => panel.GetControlFromPosition(column, 0)); } [Theory] [InlineData(-2)] [InlineData(-1)] - public void TableLayoutPanel_GetControlFromPosition_NegativeRow_ThrowsArgumentException(int row) + public void TableLayoutPanel_GetControlFromPosition_NegativeRow_ThrowsArgumentOutOfRangeException(int row) { var panel = new TableLayoutPanel(); - Assert.Throws(null, () => panel.GetControlFromPosition(0, row)); + Assert.Throws("row", () => panel.GetControlFromPosition(0, row)); } [Theory]