Skip to content

Commit 2ddc63f

Browse files
authored
Replace ArgumentNullException(nameof()) -> ArgumentNullException.ThrowIfNull() (PowerShell#18784)
1 parent b7096e8 commit 2ddc63f

122 files changed

Lines changed: 272 additions & 921 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/Microsoft.Management.UI.Internal/HelpWindow/ParagraphBuilder.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@ internal class ParagraphBuilder : INotifyPropertyChanged
4343
/// <param name="paragraph">Paragraph we will be adding lines to in BuildParagraph.</param>
4444
internal ParagraphBuilder(Paragraph paragraph)
4545
{
46-
if (paragraph == null)
47-
{
48-
throw new ArgumentNullException("paragraph");
49-
}
46+
ArgumentNullException.ThrowIfNull(paragraph);
5047

5148
this.paragraph = paragraph;
5249
this.boldSpans = new List<TextSpan>();
@@ -185,10 +182,7 @@ internal void HighlightAllInstancesOf(string search, bool caseSensitive, bool wh
185182
/// <param name="bold">True if the text should be bold.</param>
186183
internal void AddText(string str, bool bold)
187184
{
188-
if (str == null)
189-
{
190-
throw new ArgumentNullException("str");
191-
}
185+
ArgumentNullException.ThrowIfNull(str);
192186

193187
if (str.Length == 0)
194188
{

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ public class IntegralConverter : IMultiValueConverter
3131
/// </returns>
3232
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
3333
{
34-
if (values == null)
35-
{
36-
throw new ArgumentNullException("values");
37-
}
34+
ArgumentNullException.ThrowIfNull(values);
3835

3936
if (values.Length != 2)
4037
{

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ public class InverseBooleanConverter : IValueConverter
2222
/// <returns>The inverted boolean value.</returns>
2323
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
2424
{
25-
if (value == null)
26-
{
27-
throw new ArgumentNullException("value");
28-
}
25+
ArgumentNullException.ThrowIfNull(value);
2926

3027
var boolValue = (bool)value;
3128

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ public class IsEqualConverter : IMultiValueConverter
3131
/// </returns>
3232
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
3333
{
34-
if (values == null)
35-
{
36-
throw new ArgumentNullException("values");
37-
}
34+
ArgumentNullException.ThrowIfNull(values);
3835

3936
if (values.Length != 2)
4037
{

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ public class StringFormatConverter : IValueConverter
2323
/// <returns>The formatted string.</returns>
2424
public object Convert(object value, Type targetType, Object parameter, CultureInfo culture)
2525
{
26-
if (parameter == null)
27-
{
28-
throw new ArgumentNullException("parameter");
29-
}
26+
ArgumentNullException.ThrowIfNull(parameter);
3027

3128
string str = (string)value;
3229
string formatString = (string)parameter;

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,7 @@ public static class Utilities
8383
/// <exception cref="ArgumentNullException">The specified value is a null reference.</exception>
8484
public static bool AreAllItemsOfType<T>(IEnumerable items)
8585
{
86-
if (items == null)
87-
{
88-
throw new ArgumentNullException("items");
89-
}
86+
ArgumentNullException.ThrowIfNull(items);
9087

9188
foreach (object item in items)
9289
{
@@ -108,10 +105,7 @@ public static bool AreAllItemsOfType<T>(IEnumerable items)
108105
/// <exception cref="ArgumentNullException">The specified value is a null reference.</exception>
109106
public static T Find<T>(this IEnumerable items)
110107
{
111-
if (items == null)
112-
{
113-
throw new ArgumentNullException("items");
114-
}
108+
ArgumentNullException.ThrowIfNull(items);
115109

116110
foreach (object item in items)
117111
{

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,9 @@ public class VisualToAncestorDataConverter : IValueConverter
2727
/// <exception cref="ArgumentNullException">The specified value is a null reference.</exception>
2828
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
2929
{
30-
if (value == null)
31-
{
32-
throw new ArgumentNullException("value");
33-
}
30+
ArgumentNullException.ThrowIfNull(value);
3431

35-
if (parameter == null)
36-
{
37-
throw new ArgumentNullException("parameter");
38-
}
32+
ArgumentNullException.ThrowIfNull(parameter);
3933

4034
Type dataType = (Type)parameter;
4135

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ internal class WeakEventListener<TEventArgs> : IWeakEventListener where TEventAr
2020
/// <param name="handler">The handler for the event.</param>
2121
public WeakEventListener(EventHandler<TEventArgs> handler)
2222
{
23-
if (handler == null)
24-
{
25-
throw new ArgumentNullException("handler");
26-
}
23+
ArgumentNullException.ThrowIfNull(handler);
2724

2825
this.realHander = handler;
2926
}

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

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,7 @@ public bool IsEmpty
153153
/// <exception cref="NotSupportedException">The specified value does not have a parent that supports removal.</exception>
154154
public static void RemoveFromParent(FrameworkElement element)
155155
{
156-
if (element == null)
157-
{
158-
throw new ArgumentNullException("element");
159-
}
156+
ArgumentNullException.ThrowIfNull(element);
160157

161158
// If the element has already been detached, do nothing \\
162159
if (element.Parent == null)
@@ -215,10 +212,7 @@ public static void RemoveFromParent(FrameworkElement element)
215212
/// <exception cref="NotSupportedException">The specified value does not have a parent that supports removal.</exception>
216213
public static void AddChild(FrameworkElement parent, FrameworkElement element)
217214
{
218-
if (element == null)
219-
{
220-
throw new ArgumentNullException("element");
221-
}
215+
ArgumentNullException.ThrowIfNull(element);
222216

223217
if (parent == null)
224218
{
@@ -310,10 +304,8 @@ public static List<T> FindVisualChildren<T>(DependencyObject obj)
310304
where T : DependencyObject
311305
{
312306
Debug.Assert(obj != null, "obj is null");
313-
if (obj == null)
314-
{
315-
throw new ArgumentNullException("obj");
316-
}
307+
308+
ArgumentNullException.ThrowIfNull(obj);
317309

318310
List<T> childrenOfType = new List<T>();
319311

@@ -348,10 +340,7 @@ public static List<T> FindVisualChildren<T>(DependencyObject obj)
348340
public static T FindVisualAncestorData<T>(this DependencyObject obj)
349341
where T : class
350342
{
351-
if (obj == null)
352-
{
353-
throw new ArgumentNullException("obj");
354-
}
343+
ArgumentNullException.ThrowIfNull(obj);
355344

356345
FrameworkElement parent = obj.FindVisualAncestor<FrameworkElement>();
357346

@@ -413,10 +402,7 @@ public static T FindVisualAncestor<T>(this DependencyObject @object) where T : c
413402
/// <exception cref="ArgumentNullException">The specified value is a null reference.</exception>
414403
public static bool TryExecute(this RoutedCommand command, object parameter, IInputElement target)
415404
{
416-
if (command == null)
417-
{
418-
throw new ArgumentNullException("command");
419-
}
405+
ArgumentNullException.ThrowIfNull(command);
420406

421407
if (command.CanExecute(parameter, target))
422408
{
@@ -437,10 +423,7 @@ public static bool TryExecute(this RoutedCommand command, object parameter, IInp
437423
/// <returns>The reference to the child, or null if the template part wasn't found.</returns>
438424
public static T GetOptionalTemplateChild<T>(Control templateParent, string childName) where T : FrameworkElement
439425
{
440-
if (templateParent == null)
441-
{
442-
throw new ArgumentNullException("templateParent");
443-
}
426+
ArgumentNullException.ThrowIfNull(templateParent);
444427

445428
if (string.IsNullOrEmpty(childName))
446429
{
@@ -566,10 +549,7 @@ public static RoutedPropertyChangedEventArgs<T> CreateRoutedPropertyChangedEvent
566549
/// <exception cref="ArgumentOutOfRangeException">The specified index is not valid for the specified collection.</exception>
567550
public static void ChangeIndex(ItemCollection items, object item, int newIndex)
568551
{
569-
if (items == null)
570-
{
571-
throw new ArgumentNullException("items");
572-
}
552+
ArgumentNullException.ThrowIfNull(items);
573553

574554
if (!items.Contains(item))
575555
{

src/Microsoft.Management.UI.Internal/ManagementList/CommonControls/ResizerGripThicknessConverter.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ public ResizerGripThicknessConverter()
3838
/// <returns>A converted value. If the method returns nullNothingnullptra null reference (Nothing in Visual Basic), the valid null value is used.</returns>
3939
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
4040
{
41-
if (values == null)
42-
{
43-
throw new ArgumentNullException("values");
44-
}
41+
ArgumentNullException.ThrowIfNull(values);
4542

4643
if (object.ReferenceEquals(values[0], DependencyProperty.UnsetValue) ||
4744
object.ReferenceEquals(values[1], DependencyProperty.UnsetValue))

0 commit comments

Comments
 (0)