Browse Source

Modernized argument check syntax

pull/12226/head
John Doe 3 years ago
parent
commit
7f4f01b11a
  1. 4
      src/Avalonia.Base/Threading/Dispatcher.Invoke.cs
  2. 12
      src/Avalonia.Base/Threading/DispatcherTimer.cs
  3. 4
      src/Avalonia.Controls.DataGrid/Collections/DataGridCollectionView.cs
  4. 4
      src/Avalonia.Controls/Automation/Peers/ScrollViewerAutomationPeer.cs
  5. 4
      src/Avalonia.Controls/DateTimePickers/DateTimePickerPanel.cs
  6. 10
      src/Avalonia.Controls/PullToRefresh/ScrollViewerIRefreshInfoProviderAdapter.cs
  7. 2
      src/Avalonia.Controls/Utils/VirtualizingSnapPointsList.cs

4
src/Avalonia.Base/Threading/Dispatcher.Invoke.cs

@ -98,7 +98,7 @@ public partial class Dispatcher
if (timeout.TotalMilliseconds < 0 && if (timeout.TotalMilliseconds < 0 &&
timeout != TimeSpan.FromMilliseconds(-1)) timeout != TimeSpan.FromMilliseconds(-1))
{ {
throw new ArgumentOutOfRangeException("timeout"); throw new ArgumentOutOfRangeException(nameof(timeout));
} }
// Fast-Path: if on the same thread, and invoking at Send priority, // Fast-Path: if on the same thread, and invoking at Send priority,
@ -220,7 +220,7 @@ public partial class Dispatcher
if (timeout.TotalMilliseconds < 0 && if (timeout.TotalMilliseconds < 0 &&
timeout != TimeSpan.FromMilliseconds(-1)) timeout != TimeSpan.FromMilliseconds(-1))
{ {
throw new ArgumentOutOfRangeException("timeout"); throw new ArgumentOutOfRangeException(nameof(timeout));
} }
// Fast-Path: if on the same thread, and invoking at Send priority, // Fast-Path: if on the same thread, and invoking at Send priority,

12
src/Avalonia.Base/Threading/DispatcherTimer.cs

@ -112,11 +112,11 @@ public partial class DispatcherTimer
bool updateOSTimer = false; bool updateOSTimer = false;
if (value.TotalMilliseconds < 0) if (value.TotalMilliseconds < 0)
throw new ArgumentOutOfRangeException("value", throw new ArgumentOutOfRangeException(nameof(value),
"TimeSpan period must be greater than or equal to zero."); "TimeSpan period must be greater than or equal to zero.");
if (value.TotalMilliseconds > Int32.MaxValue) if (value.TotalMilliseconds > Int32.MaxValue)
throw new ArgumentOutOfRangeException("value", throw new ArgumentOutOfRangeException(nameof(value),
"TimeSpan period must be less than or equal to Int32.MaxValue."); "TimeSpan period must be less than or equal to Int32.MaxValue.");
lock (_instanceLock) lock (_instanceLock)
@ -259,14 +259,14 @@ public partial class DispatcherTimer
DispatcherPriority.Validate(priority, "priority"); DispatcherPriority.Validate(priority, "priority");
if (priority == DispatcherPriority.Inactive) if (priority == DispatcherPriority.Inactive)
{ {
throw new ArgumentException("Specified priority is not valid.", "priority"); throw new ArgumentException("Specified priority is not valid.", nameof(priority));
} }
if (interval.TotalMilliseconds < 0) if (interval.TotalMilliseconds < 0)
throw new ArgumentOutOfRangeException("interval", "TimeSpan period must be greater than or equal to zero."); throw new ArgumentOutOfRangeException(nameof(interval), "TimeSpan period must be greater than or equal to zero.");
if (interval.TotalMilliseconds > Int32.MaxValue) if (interval.TotalMilliseconds > Int32.MaxValue)
throw new ArgumentOutOfRangeException("interval", throw new ArgumentOutOfRangeException(nameof(interval),
"TimeSpan period must be less than or equal to Int32.MaxValue."); "TimeSpan period must be less than or equal to Int32.MaxValue.");
@ -349,4 +349,4 @@ public partial class DispatcherTimer
// used by Dispatcher // used by Dispatcher
internal long DueTimeInMs { get; private set; } internal long DueTimeInMs { get; private set; }
} }

4
src/Avalonia.Controls.DataGrid/Collections/DataGridCollectionView.cs

@ -807,7 +807,7 @@ namespace Avalonia.Collections
{ {
if (value < 0) if (value < 0)
{ {
throw new ArgumentOutOfRangeException("PageSize cannot have a negative value."); throw new ArgumentOutOfRangeException(nameof(value), "PageSize cannot have a negative value.");
} }
// if the Refresh is currently deferred, cache the desired PageSize // if the Refresh is currently deferred, cache the desired PageSize
@ -1954,7 +1954,7 @@ namespace Avalonia.Collections
// for indices larger than the count // for indices larger than the count
if (index >= Count || index < 0) if (index >= Count || index < 0)
{ {
throw new ArgumentOutOfRangeException("index"); throw new ArgumentOutOfRangeException(nameof(index));
} }
if (IsGrouping) if (IsGrouping)

4
src/Avalonia.Controls/Automation/Peers/ScrollViewerAutomationPeer.cs

@ -146,12 +146,12 @@ namespace Avalonia.Automation.Peers
if (scrollHorizontally && (horizontalPercent < 0.0) || (horizontalPercent > 100.0)) if (scrollHorizontally && (horizontalPercent < 0.0) || (horizontalPercent > 100.0))
{ {
throw new ArgumentOutOfRangeException("horizontalPercent"); throw new ArgumentOutOfRangeException(nameof(horizontalPercent));
} }
if (scrollVertically && (verticalPercent < 0.0) || (verticalPercent > 100.0)) if (scrollVertically && (verticalPercent < 0.0) || (verticalPercent > 100.0))
{ {
throw new ArgumentOutOfRangeException("verticalPercent"); throw new ArgumentOutOfRangeException(nameof(verticalPercent));
} }
var offset = Owner.Offset; var offset = Owner.Offset;

4
src/Avalonia.Controls/DateTimePickers/DateTimePickerPanel.cs

@ -165,7 +165,7 @@ namespace Avalonia.Controls.Primitives
set set
{ {
if (value > MaximumValue || value < MinimumValue) if (value > MaximumValue || value < MinimumValue)
throw new ArgumentOutOfRangeException("SelectedValue"); throw new ArgumentOutOfRangeException(nameof(value));
var sel = CoerceSelected(value); var sel = CoerceSelected(value);
_selectedValue = sel; _selectedValue = sel;
@ -195,7 +195,7 @@ namespace Avalonia.Controls.Primitives
set set
{ {
if (value <= 0 || value > _range) if (value <= 0 || value > _range)
throw new ArgumentOutOfRangeException("Increment"); throw new ArgumentOutOfRangeException(nameof(value));
_increment = value; _increment = value;
UpdateHelperInfo(); UpdateHelperInfo();
var sel = CoerceSelected(SelectedValue); var sel = CoerceSelected(SelectedValue);

10
src/Avalonia.Controls/PullToRefresh/ScrollViewerIRefreshInfoProviderAdapter.cs

@ -98,14 +98,14 @@ namespace Avalonia.Controls.PullToRefresh
if (_scrollViewer.Content == null) if (_scrollViewer.Content == null)
{ {
throw new ArgumentException(nameof(adaptee), "Adaptee's content property cannot be null."); throw new ArgumentException("Adaptee's content property cannot be null.", nameof(adaptee));
} }
var content = adaptee.Content as Visual; var content = adaptee.Content as Visual;
if (content == null) if (content == null)
{ {
throw new ArgumentException(nameof(adaptee), "Adaptee's content property must be a Visual"); throw new ArgumentException("Adaptee's content property must be a Visual", nameof(adaptee));
} }
if (content.GetVisualParent() == null) if (content.GetVisualParent() == null)
@ -118,7 +118,7 @@ namespace Avalonia.Controls.PullToRefresh
if (content.Parent is not InputElement) if (content.Parent is not InputElement)
{ {
throw new ArgumentException(nameof(adaptee), "Adaptee's content's parent must be a InputElement"); throw new ArgumentException("Adaptee's content's parent must be a InputElement", nameof(adaptee));
} }
} }
@ -194,12 +194,12 @@ namespace Avalonia.Controls.PullToRefresh
var content = _scrollViewer?.Content as Visual; var content = _scrollViewer?.Content as Visual;
if (content == null) if (content == null)
{ {
throw new ArgumentException(nameof(_scrollViewer), "Adaptee's content property must be a Visual"); throw new ArgumentException("Adaptee's content property must be a Visual", nameof(_scrollViewer));
} }
if (content.Parent is not InputElement parent) if (content.Parent is not InputElement parent)
{ {
throw new ArgumentException(nameof(_scrollViewer), "Adaptee's content parent must be an InputElement"); throw new ArgumentException("Adaptee's content parent must be an InputElement", nameof(_scrollViewer));
} }
MakeInteractionSource(parent); MakeInteractionSource(parent);

2
src/Avalonia.Controls/Utils/VirtualizingSnapPointsList.cs

@ -39,7 +39,7 @@ namespace Avalonia.Controls.Utils
get get
{ {
if(index < 0 || index >= Count) if(index < 0 || index >= Count)
throw new ArgumentOutOfRangeException("index"); throw new ArgumentOutOfRangeException(nameof(index));
index += _start; index += _start;

Loading…
Cancel
Save