Skip to content

Commit 8d8f45e

Browse files
authored
Use ArgumentNullException.ThrowIfNull part 2 (PowerShell#19258)
1 parent 03396c4 commit 8d8f45e

File tree

14 files changed

+36
-50
lines changed

14 files changed

+36
-50
lines changed

src/Microsoft.Management.UI.Internal/ManagementList/Common/ListOrganizer.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,15 @@ protected override void OnKeyDown(KeyEventArgs e)
4242

4343
partial void OnSelectItemExecutedImplementation(ExecutedRoutedEventArgs e)
4444
{
45-
if (e.Parameter == null)
46-
{
47-
throw new ArgumentException("e.Parameter is null", "e");
48-
}
45+
ArgumentNullException.ThrowIfNull(e.Parameter);
4946

5047
this.RaiseEvent(new DataRoutedEventArgs<object>(e.Parameter, ItemSelectedEvent));
5148
this.picker.IsOpen = false;
5249
}
5350

5451
partial void OnDeleteItemExecutedImplementation(ExecutedRoutedEventArgs e)
5552
{
56-
if (e.Parameter == null)
57-
{
58-
throw new ArgumentException("e.Parameter is null", "e");
59-
}
53+
ArgumentNullException.ThrowIfNull(e.Parameter);
6054

6155
this.RaiseEvent(new DataRoutedEventArgs<object>(e.Parameter, ItemDeletedEvent));
6256
}

src/Microsoft.Management.UI.Internal/ManagementList/FilterCore/FilterRules/PropertyValueSelectorFilterRule.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,7 @@ public PropertyValueSelectorFilterRule(string propertyName, string propertyDispl
7676

7777
foreach (FilterRule rule in rules)
7878
{
79-
if (rule == null)
80-
{
81-
throw new ArgumentException("A value within rules is null", "rules");
82-
}
79+
ArgumentNullException.ThrowIfNull(rule);
8380

8481
this.AvailableRules.AvailableValues.Add(rule);
8582
}

src/Microsoft.Management.UI.Internal/ManagementList/FilterProviders/FilterRulePanel.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,7 @@ partial void OnAddRulesExecutedImplementation(ExecutedRoutedEventArgs e)
230230
{
231231
Debug.Assert(e != null, "not null");
232232

233-
if (e.Parameter == null)
234-
{
235-
throw new ArgumentException("e.Parameter is null.", "e");
236-
}
233+
ArgumentNullException.ThrowIfNull(e.Parameter);
237234

238235
List<FilterRulePanelItem> itemsToAdd = new List<FilterRulePanelItem>();
239236

@@ -265,10 +262,7 @@ partial void OnRemoveRuleExecutedImplementation(ExecutedRoutedEventArgs e)
265262
{
266263
Debug.Assert(e != null, "not null");
267264

268-
if (e.Parameter == null)
269-
{
270-
throw new ArgumentException("e.Parameter is null.", "e");
271-
}
265+
ArgumentNullException.ThrowIfNull(e.Parameter);
272266

273267
FilterRulePanelItem item = e.Parameter as FilterRulePanelItem;
274268
if (item == null)

src/Microsoft.Management.UI.Internal/ManagementList/FilterProviders/FilterRuleToDisplayNameConverter.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ public object Convert(object value, Type targetType, object parameter, System.Gl
4141
}
4242

4343
FilterRule rule = value as FilterRule;
44-
if (rule == null)
45-
{
46-
throw new ArgumentException("value of type FilterRule expected.", "value");
47-
}
44+
ArgumentNullException.ThrowIfNull(rule);
4845

4946
return rule.DisplayName;
5047
}

src/Microsoft.Management.UI.Internal/ManagementList/ManagementList/PropertyValueGetter.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,7 @@ public virtual bool TryGetPropertyValue(string propertyName, object value, out o
4343
{
4444
propertyValue = null;
4545

46-
if (string.IsNullOrEmpty(propertyName))
47-
{
48-
throw new ArgumentException("propertyName is empty", "propertyName");
49-
}
50-
46+
ArgumentNullException.ThrowIfNullOrEmpty(propertyName);
5147
ArgumentNullException.ThrowIfNull(value);
5248

5349
PropertyDescriptor descriptor = this.GetPropertyDescriptor(propertyName, value);

src/Microsoft.Management.UI.Internal/ManagementList/ManagementList/managementlist.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,7 @@ private StateDescriptor<ManagementList> DoesViewAlreadyExist(string viewName)
340340

341341
private void ViewManager_ItemSelected(object sender, DataRoutedEventArgs<object> e)
342342
{
343-
if (e.Data == null)
344-
{
345-
throw new ArgumentException("e.Data is null", "e");
346-
}
343+
ArgumentNullException.ThrowIfNull(e.Data);
347344

348345
StateDescriptor<ManagementList> sd = (StateDescriptor<ManagementList>)e.Data;
349346
sd.RestoreState(this);
@@ -353,10 +350,7 @@ private void ViewManager_ItemSelected(object sender, DataRoutedEventArgs<object>
353350

354351
private void ViewManager_ItemDeleted(object sender, DataRoutedEventArgs<object> e)
355352
{
356-
if (e.Data == null)
357-
{
358-
throw new ArgumentException("e.Data is null", "e");
359-
}
353+
ArgumentNullException.ThrowIfNull(e.Data);
360354

361355
StateDescriptor<ManagementList> sd = (StateDescriptor<ManagementList>)e.Data;
362356
this.Views.Remove(sd);

src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/PropVariant.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ internal sealed class PropVariant : IDisposable
2929
/// </summary>
3030
internal PropVariant(string value)
3131
{
32-
if (value == null)
33-
{
34-
throw new ArgumentException("PropVariantNullString", nameof(value));
35-
}
32+
ArgumentNullException.ThrowIfNull(value);
3633

3734
#pragma warning disable CS0618 // Type or member is obsolete (might get deprecated in future versions
3835
_valueType = (ushort)VarEnum.VT_LPWSTR;

src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/EventProviderTraceListener.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ public string Delimiter
4444
ArgumentNullException.ThrowIfNull(value, nameof(Delimiter));
4545

4646
if (value.Length == 0)
47+
{
4748
throw new ArgumentException(DotNetEventingStrings.Argument_NeedNonemptyDelimiter);
49+
}
4850

4951
_delimiter = value;
5052
}
@@ -74,7 +76,9 @@ public EventProviderTraceListener(string providerId, string name, string delimit
7476
ArgumentNullException.ThrowIfNull(delimiter);
7577

7678
if (delimiter.Length == 0)
79+
{
7780
throw new ArgumentException(DotNetEventingStrings.Argument_NeedNonemptyDelimiter);
81+
}
7882

7983
_delimiter = delimiter;
8084
InitProvider(providerId);

src/System.Management.Automation/engine/hostifaces/HostUtilities.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,7 @@ internal static List<string> GetSuggestion(HistoryInfo lastHistory, object lastE
413413
{
414414
suggestion["Enabled"] = false;
415415

416-
throw new ArgumentException(
417-
SuggestionStrings.RuleMustBeScriptBlock, "Rule");
416+
throw new ArgumentException(SuggestionStrings.RuleMustBeScriptBlock, "Rule");
418417
}
419418

420419
try
@@ -482,9 +481,7 @@ internal static List<string> GetSuggestion(HistoryInfo lastHistory, object lastE
482481
{
483482
suggestion["Enabled"] = false;
484483

485-
throw new ArgumentException(
486-
SuggestionStrings.InvalidMatchType,
487-
"MatchType");
484+
throw new ArgumentException(SuggestionStrings.InvalidMatchType, "MatchType");
488485
}
489486

490487
// If the text matches, evaluate the suggestion

src/System.Management.Automation/engine/remoting/client/ThrottlingJob.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,11 @@ internal void DisableFlowControlForPendingCmdletActionsQueue()
369369
internal void AddChildJobWithoutBlocking(StartableJob childJob, ChildJobFlags flags, Action jobEnqueuedAction = null)
370370
{
371371
ArgumentNullException.ThrowIfNull(childJob);
372-
if (childJob.JobStateInfo.State != JobState.NotStarted) throw new ArgumentException(RemotingErrorIdStrings.ThrottlingJobChildAlreadyRunning, nameof(childJob));
372+
if (childJob.JobStateInfo.State != JobState.NotStarted)
373+
{
374+
throw new ArgumentException(RemotingErrorIdStrings.ThrottlingJobChildAlreadyRunning, nameof(childJob));
375+
}
376+
373377
this.AssertNotDisposed();
374378

375379
JobStateInfo newJobStateInfo = null;

0 commit comments

Comments
 (0)