Skip to content

Commit c836380

Browse files
authored
Rework ArgumentNullException (#235)
***NO_CI***
1 parent da7ea10 commit c836380

File tree

3 files changed

+14
-27
lines changed

3 files changed

+14
-27
lines changed

nanoFramework.CoreLibrary/System/Convert.cs

+8-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Runtime.CompilerServices;
@@ -479,9 +479,7 @@ public static float ToSingle(string value)
479479
/// <returns>The String representation, in base 64, of the contents of <paramref name="inArray"/>.</returns>
480480
public static string ToBase64String(byte[] inArray)
481481
{
482-
#pragma warning disable S3928 // Parameter names used into ArgumentException constructors should match an existing one
483-
if (inArray == null) throw new ArgumentNullException();
484-
#pragma warning restore S3928 // Parameter names used into ArgumentException constructors should match an existing one
482+
ArgumentNullException.ThrowIfNull(inArray);
485483

486484
return ToBase64String(inArray, 0, inArray.Length, Base64FormattingOptions.None);
487485
}
@@ -494,9 +492,7 @@ public static string ToBase64String(byte[] inArray)
494492
/// <returns>The string representation in base 64 of the elements in <paramref name="inArray"/>.</returns>
495493
public static String ToBase64String(byte[] inArray, Base64FormattingOptions options)
496494
{
497-
#pragma warning disable S3928 // Parameter names used into ArgumentException constructors should match an existing one
498-
if (inArray == null) throw new ArgumentNullException();
499-
#pragma warning restore S3928 // Parameter names used into ArgumentException constructors should match an existing one
495+
ArgumentNullException.ThrowIfNull(inArray);
500496

501497
return ToBase64String(inArray, 0, inArray.Length, options);
502498
}
@@ -523,10 +519,9 @@ public static String ToBase64String(byte[] inArray, int offset, int length)
523519
/// <returns>The string representation in base 64 of <paramref name="length"/> elements of <paramref name="inArray"/>, starting at position <paramref name="offset"/>.</returns>
524520
public static string ToBase64String(byte[] inArray, int offset, int length, Base64FormattingOptions options)
525521
{
526-
//Do data verfication
527-
#pragma warning disable S3928 // Parameter names used into ArgumentException constructors should match an existing one
528-
if (inArray == null) throw new ArgumentNullException();
529-
#pragma warning restore S3928 // Parameter names used into ArgumentException constructors should match an existing one
522+
// Do data verfication
523+
ArgumentNullException.ThrowIfNull(inArray);
524+
530525
#pragma warning disable S3928 // Parameter names used into ArgumentException constructors should match an existing one
531526
if (length < 0) throw new ArgumentOutOfRangeException();
532527
#pragma warning restore S3928 // Parameter names used into ArgumentException constructors should match an existing one
@@ -564,9 +559,8 @@ public static string ToBase64String(byte[] inArray, int offset, int length, Base
564559
/// <returns>An array of 8-bit unsigned integers equivalent to <paramref name="length"/> elements at position <paramref name="offset"/> in <paramref name="inArray"/>.</returns>
565560
public static byte[] FromBase64CharArray(char[] inArray, int offset, int length)
566561
{
567-
#pragma warning disable S3928 // Parameter names used into ArgumentException constructors should match an existing one
568-
if (inArray == null) throw new ArgumentNullException();
569-
#pragma warning restore S3928 // Parameter names used into ArgumentException constructors should match an existing one
562+
ArgumentNullException.ThrowIfNull(inArray);
563+
570564
#pragma warning disable S3928 // Parameter names used into ArgumentException constructors should match an existing one
571565
if (length < 0) throw new ArgumentOutOfRangeException();
572566
#pragma warning restore S3928 // Parameter names used into ArgumentException constructors should match an existing one

nanoFramework.CoreLibrary/System/String.cs

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Diagnostics.CodeAnalysis;
@@ -863,10 +863,7 @@ public bool Contains(string value)
863863
/// <exception cref="ArgumentNullException"><paramref name="value"/> is <see langword="null"/>.</exception>
864864
public bool StartsWith(string value)
865865
{
866-
if ((object)value == null)
867-
{
868-
throw new ArgumentNullException();
869-
}
866+
ArgumentNullException.ThrowIfNull(value);
870867

871868
if ((object)this == value)
872869
{
@@ -895,10 +892,7 @@ public bool StartsWith(string value)
895892
/// <returns><see langword="true"/> if <paramref name="value"/> matches the end of this instance; otherwise, <see langword="false"/>.</returns>
896893
public bool EndsWith(string value)
897894
{
898-
if ((object)value == null)
899-
{
900-
throw new ArgumentNullException();
901-
}
895+
ArgumentNullException.ThrowIfNull(value);
902896

903897
if ((object)this == value)
904898
{

nanoFramework.CoreLibrary/System/TargetFrameworkAttribute.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
namespace System.Runtime.Versioning
@@ -19,9 +19,8 @@ public sealed class TargetFrameworkAttribute : Attribute
1919
/// <exception cref="ArgumentNullException"></exception>
2020
public TargetFrameworkAttribute(String frameworkName)
2121
{
22-
#pragma warning disable S3928 // Parameter names used into ArgumentException constructors should match an existing one
23-
if (frameworkName == null) throw new ArgumentNullException();
24-
#pragma warning restore S3928 // Parameter names used into ArgumentException constructors should match an existing one
22+
ArgumentNullException.ThrowIfNull(frameworkName);
23+
2524
_frameworkName = frameworkName;
2625
}
2726

0 commit comments

Comments
 (0)