diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.cs
index 70cd4fb988f088..9def7541aa4c6a 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.cs
@@ -314,14 +314,7 @@ public ModuleBuilder DefineDynamicModule(string name)
private ModuleBuilder DefineDynamicModuleInternalNoLock(string name)
{
- if (name == null)
- {
- throw new ArgumentNullException(nameof(name));
- }
- if (name.Length == 0)
- {
- throw new ArgumentException(SR.Argument_EmptyName, nameof(name));
- }
+ ArgumentException.ThrowIfNullOrEmpty(name);
if (name[0] == '\0')
{
throw new ArgumentException(SR.Argument_InvalidName, nameof(name));
@@ -467,14 +460,7 @@ public override Assembly GetSatelliteAssembly(CultureInfo culture, Version? vers
/// The name of module for the look up.
private ModuleBuilder? GetDynamicModuleNoLock(string name)
{
- if (name == null)
- {
- throw new ArgumentNullException(nameof(name));
- }
- if (name.Length == 0)
- {
- throw new ArgumentException(SR.Argument_EmptyName, nameof(name));
- }
+ ArgumentException.ThrowIfNullOrEmpty(name);
for (int i = 0; i < _assemblyData._moduleBuilderList.Count; i++)
{
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/FieldBuilder.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/FieldBuilder.cs
index e4c35c9dbbc034..c3e22c5d340719 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/FieldBuilder.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/FieldBuilder.cs
@@ -20,17 +20,12 @@ public sealed class FieldBuilder : FieldInfo
internal FieldBuilder(TypeBuilder typeBuilder, string fieldName, Type type,
Type[]? requiredCustomModifiers, Type[]? optionalCustomModifiers, FieldAttributes attributes)
{
- if (fieldName == null)
- throw new ArgumentNullException(nameof(fieldName));
-
- if (fieldName.Length == 0)
- throw new ArgumentException(SR.Argument_EmptyName, nameof(fieldName));
+ ArgumentException.ThrowIfNullOrEmpty(fieldName);
if (fieldName[0] == '\0')
throw new ArgumentException(SR.Argument_IllegalName, nameof(fieldName));
- if (type == null)
- throw new ArgumentNullException(nameof(type));
+ ArgumentNullException.ThrowIfNull(type);
if (type == typeof(void))
throw new ArgumentException(SR.Argument_BadFieldType);
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.cs
index 275cecbead57a6..1b35f5cdbb15f0 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.cs
@@ -1273,11 +1273,7 @@ public virtual void UsingNamespace(string usingNamespace)
// Specifying the namespace to be used in evaluating locals and watches
// for the current active lexical scope.
- if (usingNamespace == null)
- throw new ArgumentNullException(nameof(usingNamespace));
-
- if (usingNamespace.Length == 0)
- throw new ArgumentException(SR.Argument_EmptyName, nameof(usingNamespace));
+ ArgumentException.ThrowIfNullOrEmpty(usingNamespace);
MethodBuilder? methodBuilder = m_methodBuilder as MethodBuilder;
if (methodBuilder == null)
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.cs
index 176f5a3fd37296..9d11aacaf53ea8 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.cs
@@ -61,24 +61,18 @@ internal MethodBuilder(string name, MethodAttributes attributes, CallingConventi
Type[]? parameterTypes, Type[][]? parameterTypeRequiredCustomModifiers, Type[][]? parameterTypeOptionalCustomModifiers,
ModuleBuilder mod, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TypeBuilder type)
{
- if (name == null)
- throw new ArgumentNullException(nameof(name));
-
- if (name.Length == 0)
- throw new ArgumentException(SR.Argument_EmptyName, nameof(name));
+ ArgumentException.ThrowIfNullOrEmpty(name);
if (name[0] == '\0')
throw new ArgumentException(SR.Argument_IllegalName, nameof(name));
- if (mod == null)
- throw new ArgumentNullException(nameof(mod));
+ ArgumentNullException.ThrowIfNull(mod);
if (parameterTypes != null)
{
foreach (Type t in parameterTypes)
{
- if (t == null)
- throw new ArgumentNullException(nameof(parameterTypes));
+ ArgumentNullException.ThrowIfNull(t, nameof(parameterTypes));
}
}
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.cs
index f8b8c1efd35d03..cbe0a7b39dde5b 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.cs
@@ -948,14 +948,7 @@ private MethodBuilder DefineGlobalMethodNoLock(string name, MethodAttributes att
{
throw new InvalidOperationException(SR.InvalidOperation_GlobalsHaveBeenCreated);
}
- if (name == null)
- {
- throw new ArgumentNullException(nameof(name));
- }
- if (name.Length == 0)
- {
- throw new ArgumentException(SR.Argument_EmptyName, nameof(name));
- }
+ ArgumentException.ThrowIfNullOrEmpty(name);
if ((attributes & MethodAttributes.Static) == 0)
{
throw new ArgumentException(SR.Argument_GlobalFunctionHasToBeStatic);
@@ -1352,18 +1345,8 @@ internal int GetArrayMethodToken(Type arrayClass, string methodName, CallingConv
private int GetArrayMethodTokenNoLock(Type arrayClass, string methodName, CallingConventions callingConvention,
Type? returnType, Type[]? parameterTypes)
{
- if (arrayClass == null)
- {
- throw new ArgumentNullException(nameof(arrayClass));
- }
- if (methodName == null)
- {
- throw new ArgumentNullException(nameof(methodName));
- }
- if (methodName.Length == 0)
- {
- throw new ArgumentException(SR.Argument_EmptyName, nameof(methodName));
- }
+ ArgumentNullException.ThrowIfNull(arrayClass);
+ ArgumentException.ThrowIfNullOrEmpty(methodName);
if (!arrayClass.IsArray)
{
throw new ArgumentException(SR.Argument_HasToBeArrayClass);
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/PropertyBuilder.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/PropertyBuilder.cs
index ae6e704b2a5c87..89accc39caeb98 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/PropertyBuilder.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/PropertyBuilder.cs
@@ -34,10 +34,7 @@ internal PropertyBuilder(
int prToken, // the metadata token for this property
TypeBuilder containingType) // the containing type
{
- if (name == null)
- throw new ArgumentNullException(nameof(name));
- if (name.Length == 0)
- throw new ArgumentException(SR.Argument_EmptyName, nameof(name));
+ ArgumentException.ThrowIfNullOrEmpty(name);
if (name[0] == '\0')
throw new ArgumentException(SR.Argument_IllegalName, nameof(name));
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs
index a242ec948896be..ad80acad078350 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs
@@ -480,11 +480,7 @@ internal TypeBuilder(
string fullname, TypeAttributes attr, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type? parent, Type[]? interfaces, ModuleBuilder module,
PackingSize iPackingSize, int iTypeSize, TypeBuilder? enclosingType)
{
- if (fullname == null)
- throw new ArgumentNullException(nameof(fullname));
-
- if (fullname.Length == 0)
- throw new ArgumentException(SR.Argument_EmptyName, nameof(fullname));
+ ArgumentException.ThrowIfNullOrEmpty(fullname);
if (fullname[0] == '\0')
throw new ArgumentException(SR.Argument_IllegalName, nameof(fullname));
@@ -581,11 +577,7 @@ private FieldBuilder DefineDataHelper(string name, byte[]? data, int size, Field
FieldBuilder fdBuilder;
TypeAttributes typeAttributes;
- if (name == null)
- throw new ArgumentNullException(nameof(name));
-
- if (name.Length == 0)
- throw new ArgumentException(SR.Argument_EmptyName, nameof(name));
+ ArgumentException.ThrowIfNullOrEmpty(name);
if (size <= 0 || size >= 0x003f0000)
throw new ArgumentException(SR.Argument_BadSizeForData);
@@ -1282,11 +1274,7 @@ private MethodBuilder DefineMethodNoLock(string name, MethodAttributes attribute
Type? returnType, Type[]? returnTypeRequiredCustomModifiers, Type[]? returnTypeOptionalCustomModifiers,
Type[]? parameterTypes, Type[][]? parameterTypeRequiredCustomModifiers, Type[][]? parameterTypeOptionalCustomModifiers)
{
- if (name == null)
- throw new ArgumentNullException(nameof(name));
-
- if (name.Length == 0)
- throw new ArgumentException(SR.Argument_EmptyName, nameof(name));
+ ArgumentException.ThrowIfNullOrEmpty(name);
AssemblyBuilder.CheckContext(returnType);
AssemblyBuilder.CheckContext(returnTypeRequiredCustomModifiers, returnTypeOptionalCustomModifiers, parameterTypes);
@@ -1374,23 +1362,9 @@ private MethodBuilder DefinePInvokeMethodHelper(
lock (SyncRoot)
{
- if (name == null)
- throw new ArgumentNullException(nameof(name));
-
- if (name.Length == 0)
- throw new ArgumentException(SR.Argument_EmptyName, nameof(name));
-
- if (dllName == null)
- throw new ArgumentNullException(nameof(dllName));
-
- if (dllName.Length == 0)
- throw new ArgumentException(SR.Argument_EmptyName, nameof(dllName));
-
- if (importName == null)
- throw new ArgumentNullException(nameof(importName));
-
- if (importName.Length == 0)
- throw new ArgumentException(SR.Argument_EmptyName, nameof(importName));
+ ArgumentException.ThrowIfNullOrEmpty(name);
+ ArgumentException.ThrowIfNullOrEmpty(dllName);
+ ArgumentException.ThrowIfNullOrEmpty(importName);
if ((attributes & MethodAttributes.Abstract) != 0)
throw new ArgumentException(SR.Argument_BadPInvokeMethod);
@@ -1792,10 +1766,7 @@ private PropertyBuilder DefinePropertyNoLock(string name, PropertyAttributes att
Type returnType, Type[]? returnTypeRequiredCustomModifiers, Type[]? returnTypeOptionalCustomModifiers,
Type[]? parameterTypes, Type[][]? parameterTypeRequiredCustomModifiers, Type[][]? parameterTypeOptionalCustomModifiers)
{
- if (name == null)
- throw new ArgumentNullException(nameof(name));
- if (name.Length == 0)
- throw new ArgumentException(SR.Argument_EmptyName, nameof(name));
+ ArgumentException.ThrowIfNullOrEmpty(name);
AssemblyBuilder.CheckContext(returnType);
AssemblyBuilder.CheckContext(returnTypeRequiredCustomModifiers, returnTypeOptionalCustomModifiers, parameterTypes);
@@ -1847,10 +1818,7 @@ public EventBuilder DefineEvent(string name, EventAttributes attributes, Type ev
private EventBuilder DefineEventNoLock(string name, EventAttributes attributes, Type eventtype)
{
- if (name == null)
- throw new ArgumentNullException(nameof(name));
- if (name.Length == 0)
- throw new ArgumentException(SR.Argument_EmptyName, nameof(name));
+ ArgumentException.ThrowIfNullOrEmpty(name);
if (name[0] == '\0')
throw new ArgumentException(SR.Argument_IllegalName, nameof(name));
diff --git a/src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs b/src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs
index 32a37b6d4219f1..3708e71cb4510b 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs
@@ -558,8 +558,7 @@ private static partial void GetTypeByName(string name, bool throwOnError, bool i
internal static RuntimeType GetTypeByNameUsingCARules(string name, RuntimeModule scope)
{
- if (string.IsNullOrEmpty(name))
- throw new ArgumentException(null, nameof(name));
+ ArgumentException.ThrowIfNullOrEmpty(name);
RuntimeType? type = null;
GetTypeByNameUsingCARules(name, new QCallModule(ref scope), ObjectHandleOnStack.Create(ref type));
diff --git a/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanAndroid.Derive.cs b/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanAndroid.Derive.cs
index a0b8af82113da7..dc902e555081bc 100644
--- a/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanAndroid.Derive.cs
+++ b/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanAndroid.Derive.cs
@@ -23,10 +23,8 @@ public override byte[] DeriveKeyFromHash(
byte[]? secretPrepend,
byte[]? secretAppend)
{
- if (otherPartyPublicKey == null)
- throw new ArgumentNullException(nameof(otherPartyPublicKey));
- if (string.IsNullOrEmpty(hashAlgorithm.Name))
- throw new ArgumentException(SR.Cryptography_HashAlgorithmNameNullOrEmpty, nameof(hashAlgorithm));
+ ArgumentNullException.ThrowIfNull(otherPartyPublicKey);
+ ArgumentException.ThrowIfNullOrEmpty(hashAlgorithm.Name, nameof(hashAlgorithm));
ThrowIfDisposed();
@@ -45,10 +43,8 @@ public override byte[] DeriveKeyFromHmac(
byte[]? secretPrepend,
byte[]? secretAppend)
{
- if (otherPartyPublicKey == null)
- throw new ArgumentNullException(nameof(otherPartyPublicKey));
- if (string.IsNullOrEmpty(hashAlgorithm.Name))
- throw new ArgumentException(SR.Cryptography_HashAlgorithmNameNullOrEmpty, nameof(hashAlgorithm));
+ ArgumentNullException.ThrowIfNull(otherPartyPublicKey);
+ ArgumentException.ThrowIfNullOrEmpty(hashAlgorithm.Name, nameof(hashAlgorithm));
ThrowIfDisposed();
diff --git a/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanCng.cs b/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanCng.cs
index 90d2e4f01145c0..ad955d55ce8eed 100644
--- a/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanCng.cs
+++ b/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanCng.cs
@@ -76,10 +76,8 @@ public override byte[] DeriveKeyFromHash(
byte[]? secretPrepend,
byte[]? secretAppend)
{
- if (otherPartyPublicKey == null)
- throw new ArgumentNullException(nameof(otherPartyPublicKey));
- if (string.IsNullOrEmpty(hashAlgorithm.Name))
- throw new ArgumentException(SR.Cryptography_HashAlgorithmNameNullOrEmpty, nameof(hashAlgorithm));
+ ArgumentNullException.ThrowIfNull(otherPartyPublicKey);
+ ArgumentException.ThrowIfNullOrEmpty(hashAlgorithm.Name, nameof(hashAlgorithm));
using (SafeNCryptSecretHandle secretAgreement = DeriveSecretAgreementHandle(otherPartyPublicKey))
{
@@ -99,10 +97,8 @@ public override byte[] DeriveKeyFromHmac(
byte[]? secretPrepend,
byte[]? secretAppend)
{
- if (otherPartyPublicKey == null)
- throw new ArgumentNullException(nameof(otherPartyPublicKey));
- if (string.IsNullOrEmpty(hashAlgorithm.Name))
- throw new ArgumentException(SR.Cryptography_HashAlgorithmNameNullOrEmpty, nameof(hashAlgorithm));
+ ArgumentNullException.ThrowIfNull(otherPartyPublicKey);
+ ArgumentException.ThrowIfNullOrEmpty(hashAlgorithm.Name, nameof(hashAlgorithm));
using (SafeNCryptSecretHandle secretAgreement = DeriveSecretAgreementHandle(otherPartyPublicKey))
{
diff --git a/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanOpenSsl.Derive.cs b/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanOpenSsl.Derive.cs
index 11638ed44be8a7..9d32a702bf07fa 100644
--- a/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanOpenSsl.Derive.cs
+++ b/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanOpenSsl.Derive.cs
@@ -24,10 +24,8 @@ public override byte[] DeriveKeyFromHash(
byte[]? secretPrepend,
byte[]? secretAppend)
{
- if (otherPartyPublicKey == null)
- throw new ArgumentNullException(nameof(otherPartyPublicKey));
- if (string.IsNullOrEmpty(hashAlgorithm.Name))
- throw new ArgumentException(SR.Cryptography_HashAlgorithmNameNullOrEmpty, nameof(hashAlgorithm));
+ ArgumentNullException.ThrowIfNull(otherPartyPublicKey);
+ ArgumentException.ThrowIfNullOrEmpty(hashAlgorithm.Name, nameof(hashAlgorithm));
ThrowIfDisposed();
@@ -46,10 +44,8 @@ public override byte[] DeriveKeyFromHmac(
byte[]? secretPrepend,
byte[]? secretAppend)
{
- if (otherPartyPublicKey == null)
- throw new ArgumentNullException(nameof(otherPartyPublicKey));
- if (string.IsNullOrEmpty(hashAlgorithm.Name))
- throw new ArgumentException(SR.Cryptography_HashAlgorithmNameNullOrEmpty, nameof(hashAlgorithm));
+ ArgumentNullException.ThrowIfNull(otherPartyPublicKey);
+ ArgumentException.ThrowIfNullOrEmpty(hashAlgorithm.Name, nameof(hashAlgorithm));
ThrowIfDisposed();
diff --git a/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanSecurityTransforms.cs b/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanSecurityTransforms.cs
index 214bc96f8b0e95..df1a7fae8e39a0 100644
--- a/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanSecurityTransforms.cs
+++ b/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanSecurityTransforms.cs
@@ -121,10 +121,8 @@ public override byte[] DeriveKeyFromHash(
byte[]? secretPrepend,
byte[]? secretAppend)
{
- if (otherPartyPublicKey == null)
- throw new ArgumentNullException(nameof(otherPartyPublicKey));
- if (string.IsNullOrEmpty(hashAlgorithm.Name))
- throw new ArgumentException(SR.Cryptography_HashAlgorithmNameNullOrEmpty, nameof(hashAlgorithm));
+ ArgumentNullException.ThrowIfNull(otherPartyPublicKey);
+ ArgumentException.ThrowIfNullOrEmpty(hashAlgorithm.Name, nameof(hashAlgorithm));
ThrowIfDisposed();
@@ -143,10 +141,8 @@ public override byte[] DeriveKeyFromHmac(
byte[]? secretPrepend,
byte[]? secretAppend)
{
- if (otherPartyPublicKey == null)
- throw new ArgumentNullException(nameof(otherPartyPublicKey));
- if (string.IsNullOrEmpty(hashAlgorithm.Name))
- throw new ArgumentException(SR.Cryptography_HashAlgorithmNameNullOrEmpty, nameof(hashAlgorithm));
+ ArgumentNullException.ThrowIfNull(otherPartyPublicKey);
+ ArgumentException.ThrowIfNullOrEmpty(hashAlgorithm.Name, nameof(hashAlgorithm));
ThrowIfDisposed();
diff --git a/src/libraries/Common/src/System/Security/Cryptography/RSAAndroid.cs b/src/libraries/Common/src/System/Security/Cryptography/RSAAndroid.cs
index c78de735480356..86d98f5014f6cc 100644
--- a/src/libraries/Common/src/System/Security/Cryptography/RSAAndroid.cs
+++ b/src/libraries/Common/src/System/Security/Cryptography/RSAAndroid.cs
@@ -678,12 +678,9 @@ protected override bool TryHashData(ReadOnlySpan data, Span destinat
public override byte[] SignHash(byte[] hash, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
{
- if (hash == null)
- throw new ArgumentNullException(nameof(hash));
- if (string.IsNullOrEmpty(hashAlgorithm.Name))
- throw HashAlgorithmNameNullOrEmpty();
- if (padding == null)
- throw new ArgumentNullException(nameof(padding));
+ ArgumentNullException.ThrowIfNull(hash);
+ ArgumentException.ThrowIfNullOrEmpty(hashAlgorithm.Name, nameof(hashAlgorithm));
+ ArgumentNullException.ThrowIfNull(padding);
if (!TrySignHash(
hash,
@@ -708,14 +705,8 @@ public override bool TrySignHash(
RSASignaturePadding padding,
out int bytesWritten)
{
- if (string.IsNullOrEmpty(hashAlgorithm.Name))
- {
- throw HashAlgorithmNameNullOrEmpty();
- }
- if (padding == null)
- {
- throw new ArgumentNullException(nameof(padding));
- }
+ ArgumentException.ThrowIfNullOrEmpty(hashAlgorithm.Name, nameof(hashAlgorithm));
+ ArgumentNullException.ThrowIfNull(padding);
bool ret = TrySignHash(
hash,
@@ -817,14 +808,8 @@ public override bool VerifyHash(
public override bool VerifyHash(ReadOnlySpan hash, ReadOnlySpan signature, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
{
- if (string.IsNullOrEmpty(hashAlgorithm.Name))
- {
- throw HashAlgorithmNameNullOrEmpty();
- }
- if (padding == null)
- {
- throw new ArgumentNullException(nameof(padding));
- }
+ ArgumentException.ThrowIfNullOrEmpty(hashAlgorithm.Name, nameof(hashAlgorithm));
+ ArgumentNullException.ThrowIfNull(padding);
if (padding != RSASignaturePadding.Pkcs1 && padding != RSASignaturePadding.Pss)
{
throw PaddingModeNotSupported();
@@ -894,9 +879,6 @@ public override bool VerifyHash(ReadOnlySpan hash, ReadOnlySpan sign
private static Exception PaddingModeNotSupported() =>
new CryptographicException(SR.Cryptography_InvalidPaddingMode);
-
- private static Exception HashAlgorithmNameNullOrEmpty() =>
- new ArgumentException(SR.Cryptography_HashAlgorithmNameNullOrEmpty, "hashAlgorithm");
}
}
}
diff --git a/src/libraries/Common/src/System/Security/Cryptography/RSACng.SignVerify.cs b/src/libraries/Common/src/System/Security/Cryptography/RSACng.SignVerify.cs
index 82709832cd88de..27fc35493783f6 100644
--- a/src/libraries/Common/src/System/Security/Cryptography/RSACng.SignVerify.cs
+++ b/src/libraries/Common/src/System/Security/Cryptography/RSACng.SignVerify.cs
@@ -52,14 +52,9 @@ public override byte[] SignHash(byte[] hash, HashAlgorithmName hashAlgorithm, RS
}
string? hashAlgorithmName = hashAlgorithm.Name;
- if (string.IsNullOrEmpty(hashAlgorithmName))
- {
- throw new ArgumentException(SR.Cryptography_HashAlgorithmNameNullOrEmpty, nameof(hashAlgorithm));
- }
- if (padding == null)
- {
- throw new ArgumentNullException(nameof(padding));
- }
+ ArgumentException.ThrowIfNullOrEmpty(hashAlgorithmName, nameof(hashAlgorithm));
+
+ ArgumentNullException.ThrowIfNull(padding);
if (hash.Length != GetHashSizeInBytes(hashAlgorithm))
{
@@ -99,14 +94,8 @@ public override byte[] SignHash(byte[] hash, HashAlgorithmName hashAlgorithm, RS
public override unsafe bool TrySignHash(ReadOnlySpan hash, Span destination, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding, out int bytesWritten)
{
string? hashAlgorithmName = hashAlgorithm.Name;
- if (string.IsNullOrEmpty(hashAlgorithmName))
- {
- throw new ArgumentException(SR.Cryptography_HashAlgorithmNameNullOrEmpty, nameof(hashAlgorithm));
- }
- if (padding == null)
- {
- throw new ArgumentNullException(nameof(padding));
- }
+ ArgumentException.ThrowIfNullOrEmpty(hashAlgorithmName, nameof(hashAlgorithm));
+ ArgumentNullException.ThrowIfNull(padding);
using (SafeNCryptKeyHandle keyHandle = GetDuplicatedKeyHandle())
{
@@ -159,14 +148,8 @@ public override bool VerifyHash(byte[] hash, byte[] signature, HashAlgorithmName
public override unsafe bool VerifyHash(ReadOnlySpan hash, ReadOnlySpan signature, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
{
string? hashAlgorithmName = hashAlgorithm.Name;
- if (string.IsNullOrEmpty(hashAlgorithmName))
- {
- throw new ArgumentException(SR.Cryptography_HashAlgorithmNameNullOrEmpty, nameof(hashAlgorithm));
- }
- if (padding == null)
- {
- throw new ArgumentNullException(nameof(padding));
- }
+ ArgumentException.ThrowIfNullOrEmpty(hashAlgorithmName, nameof(hashAlgorithm));
+ ArgumentNullException.ThrowIfNull(padding);
using (SafeNCryptKeyHandle keyHandle = GetDuplicatedKeyHandle())
{
diff --git a/src/libraries/Common/src/System/Security/Cryptography/RSAOpenSsl.cs b/src/libraries/Common/src/System/Security/Cryptography/RSAOpenSsl.cs
index 149e240893039b..def40a8d5685a9 100644
--- a/src/libraries/Common/src/System/Security/Cryptography/RSAOpenSsl.cs
+++ b/src/libraries/Common/src/System/Security/Cryptography/RSAOpenSsl.cs
@@ -750,12 +750,9 @@ protected override bool TryHashData(ReadOnlySpan data, Span destinat
public override byte[] SignHash(byte[] hash, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
{
- if (hash == null)
- throw new ArgumentNullException(nameof(hash));
- if (string.IsNullOrEmpty(hashAlgorithm.Name))
- throw HashAlgorithmNameNullOrEmpty();
- if (padding == null)
- throw new ArgumentNullException(nameof(padding));
+ ArgumentNullException.ThrowIfNull(hash);
+ ArgumentException.ThrowIfNullOrEmpty(hashAlgorithm.Name, nameof(hashAlgorithm));
+ ArgumentNullException.ThrowIfNull(padding);
if (!TrySignHash(
hash,
@@ -780,14 +777,8 @@ public override bool TrySignHash(
RSASignaturePadding padding,
out int bytesWritten)
{
- if (string.IsNullOrEmpty(hashAlgorithm.Name))
- {
- throw HashAlgorithmNameNullOrEmpty();
- }
- if (padding == null)
- {
- throw new ArgumentNullException(nameof(padding));
- }
+ ArgumentException.ThrowIfNullOrEmpty(hashAlgorithm.Name, nameof(hashAlgorithm));
+ ArgumentNullException.ThrowIfNull(padding);
bool ret = TrySignHash(
hash,
@@ -860,11 +851,7 @@ public override bool VerifyHash(
public override bool VerifyHash(ReadOnlySpan hash, ReadOnlySpan signature, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
{
- if (string.IsNullOrEmpty(hashAlgorithm.Name))
- {
- throw HashAlgorithmNameNullOrEmpty();
- }
-
+ ArgumentException.ThrowIfNullOrEmpty(hashAlgorithm.Name, nameof(hashAlgorithm));
ValidatePadding(padding);
IntPtr digestAlgorithm = Interop.Crypto.HashAlgorithmToEvp(hashAlgorithm.Name);
@@ -951,9 +938,6 @@ private static void ValidatePadding(RSASignaturePadding padding)
private static Exception PaddingModeNotSupported() =>
new CryptographicException(SR.Cryptography_InvalidPaddingMode);
-
- private static Exception HashAlgorithmNameNullOrEmpty() =>
- new ArgumentException(SR.Cryptography_HashAlgorithmNameNullOrEmpty, "hashAlgorithm");
}
#if INTERNAL_ASYMMETRIC_IMPLEMENTATIONS
}
diff --git a/src/libraries/Common/src/System/Security/Cryptography/RSASecurityTransforms.cs b/src/libraries/Common/src/System/Security/Cryptography/RSASecurityTransforms.cs
index 7bce2648d443a9..190c7e4d53c9e2 100644
--- a/src/libraries/Common/src/System/Security/Cryptography/RSASecurityTransforms.cs
+++ b/src/libraries/Common/src/System/Security/Cryptography/RSASecurityTransforms.cs
@@ -386,12 +386,9 @@ private bool TryDecrypt(
public override byte[] SignHash(byte[] hash, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
{
- if (hash == null)
- throw new ArgumentNullException(nameof(hash));
- if (string.IsNullOrEmpty(hashAlgorithm.Name))
- throw HashAlgorithmNameNullOrEmpty();
- if (padding == null)
- throw new ArgumentNullException(nameof(padding));
+ ArgumentNullException.ThrowIfNull(hash);
+ ArgumentException.ThrowIfNullOrEmpty(hashAlgorithm.Name, nameof(hashAlgorithm));
+ ArgumentNullException.ThrowIfNull(padding);
ThrowIfDisposed();
@@ -443,14 +440,8 @@ public override byte[] SignHash(byte[] hash, HashAlgorithmName hashAlgorithm, RS
public override bool TrySignHash(ReadOnlySpan hash, Span destination, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding, out int bytesWritten)
{
- if (string.IsNullOrEmpty(hashAlgorithm.Name))
- {
- throw HashAlgorithmNameNullOrEmpty();
- }
- if (padding == null)
- {
- throw new ArgumentNullException(nameof(padding));
- }
+ ArgumentException.ThrowIfNullOrEmpty(hashAlgorithm.Name, nameof(hashAlgorithm));
+ ArgumentNullException.ThrowIfNull(padding);
ThrowIfDisposed();
@@ -550,14 +541,8 @@ public override bool VerifyHash(
public override bool VerifyHash(ReadOnlySpan hash, ReadOnlySpan signature, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
{
- if (string.IsNullOrEmpty(hashAlgorithm.Name))
- {
- throw HashAlgorithmNameNullOrEmpty();
- }
- if (padding == null)
- {
- throw new ArgumentNullException(nameof(padding));
- }
+ ArgumentException.ThrowIfNullOrEmpty(hashAlgorithm.Name, nameof(hashAlgorithm));
+ ArgumentNullException.ThrowIfNull(padding);
ThrowIfDisposed();
@@ -795,8 +780,5 @@ private static bool HasConsistentPrivateKey(in RSAParameters parameters)
return true;
}
}
-
- private static Exception HashAlgorithmNameNullOrEmpty() =>
- new ArgumentException(SR.Cryptography_HashAlgorithmNameNullOrEmpty, "hashAlgorithm");
}
}
diff --git a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/DSA/DsaFamilySignatureFormatTests.cs b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/DSA/DsaFamilySignatureFormatTests.cs
index b311193948a3a7..e214765dd47139 100644
--- a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/DSA/DsaFamilySignatureFormatTests.cs
+++ b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/DSA/DsaFamilySignatureFormatTests.cs
@@ -337,13 +337,21 @@ public void EmptyHashAlgorithm()
foreach (DSASignatureFormat format in Enum.GetValues(typeof(DSASignatureFormat)))
{
- AssertExtensions.Throws(
+ AssertExtensions.Throws(
"hashAlgorithm",
() => SignData(key, empty, default, format));
- AssertExtensions.Throws(
+ AssertExtensions.Throws(
"hashAlgorithm",
() => VerifyData(key, empty, empty, default, format));
+
+ AssertExtensions.Throws(
+ "hashAlgorithm",
+ () => SignData(key, empty, new HashAlgorithmName(""), format));
+
+ AssertExtensions.Throws(
+ "hashAlgorithm",
+ () => VerifyData(key, empty, empty, new HashAlgorithmName(""), format));
}
}
diff --git a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/ECDsa/ECDsaTests.cs b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/ECDsa/ECDsaTests.cs
index d747aec14e5517..187c76ad351a9f 100644
--- a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/ECDsa/ECDsaTests.cs
+++ b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/ECDsa/ECDsaTests.cs
@@ -40,9 +40,9 @@ public void SignData_InvalidArguments_Throws(ECDsa ecdsa)
AssertExtensions.Throws("count", () => ecdsa.SignData(new byte[0], 0, -1, default(HashAlgorithmName)));
AssertExtensions.Throws("count", () => ecdsa.SignData(new byte[0], 0, 1, default(HashAlgorithmName)));
- AssertExtensions.Throws("hashAlgorithm", () => ecdsa.SignData(new byte[0], default(HashAlgorithmName)));
- AssertExtensions.Throws("hashAlgorithm", () => ecdsa.SignData(new byte[0], 0, 0, default(HashAlgorithmName)));
- AssertExtensions.Throws("hashAlgorithm", () => ecdsa.SignData(new byte[0], 0, 0, default(HashAlgorithmName)));
+ AssertExtensions.Throws("hashAlgorithm", () => ecdsa.SignData(new byte[0], default(HashAlgorithmName)));
+ AssertExtensions.Throws("hashAlgorithm", () => ecdsa.SignData(new byte[0], 0, 0, default(HashAlgorithmName)));
+ AssertExtensions.Throws("hashAlgorithm", () => ecdsa.SignData(new byte[0], 0, 0, default(HashAlgorithmName)));
AssertExtensions.Throws("hashAlgorithm", () => ecdsa.SignData(new byte[10], 0, 10, new HashAlgorithmName("")));
Assert.ThrowsAny(() => ecdsa.SignData(new byte[0], new HashAlgorithmName(Guid.NewGuid().ToString("N"))));
@@ -64,8 +64,8 @@ public void VerifyData_InvalidArguments_Throws(ECDsa ecdsa)
AssertExtensions.Throws("count", () => ecdsa.VerifyData(new byte[0], 0, -1, null, default(HashAlgorithmName)));
AssertExtensions.Throws("count", () => ecdsa.VerifyData(new byte[0], 0, 1, null, default(HashAlgorithmName)));
- AssertExtensions.Throws("hashAlgorithm", () => ecdsa.VerifyData(new byte[0], new byte[0], default(HashAlgorithmName)));
- AssertExtensions.Throws("hashAlgorithm", () => ecdsa.VerifyData(new byte[0], 0, 0, new byte[0], default(HashAlgorithmName)));
+ AssertExtensions.Throws("hashAlgorithm", () => ecdsa.VerifyData(new byte[0], new byte[0], default(HashAlgorithmName)));
+ AssertExtensions.Throws("hashAlgorithm", () => ecdsa.VerifyData(new byte[0], 0, 0, new byte[0], default(HashAlgorithmName)));
AssertExtensions.Throws("hashAlgorithm", () => ecdsa.VerifyData(new byte[10], new byte[0], new HashAlgorithmName("")));
AssertExtensions.Throws("hashAlgorithm", () => ecdsa.VerifyData(new byte[10], 0, 10, new byte[0], new HashAlgorithmName("")));
@@ -110,7 +110,8 @@ protected override byte[] SignData(ECDsa ecdsa, byte[] data, int offset, int cou
public void SignData_InvalidArguments_Throws(ECDsa ecdsa)
{
AssertExtensions.Throws("data", () => ecdsa.SignData((Stream)null, default(HashAlgorithmName)));
- AssertExtensions.Throws("hashAlgorithm", () => ecdsa.SignData(new MemoryStream(), default(HashAlgorithmName)));
+ AssertExtensions.Throws("hashAlgorithm", () => ecdsa.SignData(new MemoryStream(), default(HashAlgorithmName)));
+ AssertExtensions.Throws("hashAlgorithm", () => ecdsa.SignData(new MemoryStream(), new HashAlgorithmName("")));
Assert.ThrowsAny(() => ecdsa.SignData(new MemoryStream(), new HashAlgorithmName(Guid.NewGuid().ToString("N"))));
}
@@ -119,7 +120,7 @@ public void VerifyData_InvalidArguments_Throws(ECDsa ecdsa)
{
AssertExtensions.Throws("data", () => ecdsa.VerifyData((Stream)null, null, default(HashAlgorithmName)));
AssertExtensions.Throws("signature", () => ecdsa.VerifyData(new MemoryStream(), null, default(HashAlgorithmName)));
- AssertExtensions.Throws("hashAlgorithm", () => ecdsa.VerifyData(new MemoryStream(), new byte[0], default(HashAlgorithmName)));
+ AssertExtensions.Throws("hashAlgorithm", () => ecdsa.VerifyData(new MemoryStream(), new byte[0], default(HashAlgorithmName)));
AssertExtensions.Throws("hashAlgorithm", () => ecdsa.VerifyData(new MemoryStream(), new byte[0], new HashAlgorithmName("")));
Assert.ThrowsAny(() => ecdsa.VerifyData(new MemoryStream(), new byte[0], new HashAlgorithmName(Guid.NewGuid().ToString("N"))));
}
diff --git a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/ECDsa/ECDsaTests.netcoreapp.cs b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/ECDsa/ECDsaTests.netcoreapp.cs
index eb12b87acba738..0f6a191e31dd0a 100644
--- a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/ECDsa/ECDsaTests.netcoreapp.cs
+++ b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/ECDsa/ECDsaTests.netcoreapp.cs
@@ -28,7 +28,7 @@ protected override void UseAfterDispose(ECDsa ecdsa, byte[] data, byte[] sig)
[Theory, MemberData(nameof(RealImplementations))]
public void SignData_InvalidArguments_Throws(ECDsa ecdsa)
{
- AssertExtensions.Throws("hashAlgorithm", () => ecdsa.TrySignData(ReadOnlySpan.Empty, Span.Empty, new HashAlgorithmName(null), out int bytesWritten));
+ AssertExtensions.Throws("hashAlgorithm", () => ecdsa.TrySignData(ReadOnlySpan.Empty, Span.Empty, new HashAlgorithmName(null), out int bytesWritten));
AssertExtensions.Throws("hashAlgorithm", () => ecdsa.TrySignData(ReadOnlySpan.Empty, Span.Empty, new HashAlgorithmName(""), out int bytesWritten));
Assert.ThrowsAny(() => ecdsa.TrySignData(ReadOnlySpan.Empty, Span.Empty, new HashAlgorithmName(Guid.NewGuid().ToString("N")), out int bytesWritten));
}
@@ -36,7 +36,7 @@ public void SignData_InvalidArguments_Throws(ECDsa ecdsa)
[Theory, MemberData(nameof(RealImplementations))]
public void VerifyData_InvalidArguments_Throws(ECDsa ecdsa)
{
- AssertExtensions.Throws("hashAlgorithm", () => ecdsa.VerifyData(ReadOnlySpan.Empty, ReadOnlySpan.Empty, new HashAlgorithmName(null)));
+ AssertExtensions.Throws("hashAlgorithm", () => ecdsa.VerifyData(ReadOnlySpan.Empty, ReadOnlySpan.Empty, new HashAlgorithmName(null)));
AssertExtensions.Throws("hashAlgorithm", () => ecdsa.VerifyData(ReadOnlySpan.Empty, ReadOnlySpan.Empty, new HashAlgorithmName("")));
Assert.ThrowsAny(() => ecdsa.VerifyData(ReadOnlySpan.Empty, Span.Empty, new HashAlgorithmName(Guid.NewGuid().ToString("N"))));
}
diff --git a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/SignVerify.cs b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/SignVerify.cs
index 4a7dace2695205..e78cea374bac53 100644
--- a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/SignVerify.cs
+++ b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/SignVerify.cs
@@ -48,14 +48,18 @@ public abstract class SignVerify
protected abstract bool VerifyData(RSA rsa, byte[] data, byte[] signature, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding);
protected abstract bool VerifyHash(RSA rsa, byte[] hash, byte[] signature, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding);
- [Theory]
- [InlineData(null)]
- [InlineData("")]
- public void InvalidHashAlgorithmName_Throws(string name)
+ [Fact]
+ public void InvalidHashAlgorithmName_Throws()
{
using (RSA rsa = RSAFactory.Create())
{
- var invalidName = new HashAlgorithmName(name);
+ var invalidName = new HashAlgorithmName(null);
+ AssertExtensions.Throws("hashAlgorithm", () => SignData(rsa, new byte[1], invalidName, RSASignaturePadding.Pkcs1));
+ AssertExtensions.Throws("hashAlgorithm", () => SignHash(rsa, new byte[1], invalidName, RSASignaturePadding.Pkcs1));
+ AssertExtensions.Throws("hashAlgorithm", () => VerifyData(rsa, new byte[1], new byte[1], invalidName, RSASignaturePadding.Pkcs1));
+ AssertExtensions.Throws("hashAlgorithm", () => VerifyHash(rsa, new byte[1], new byte[1], invalidName, RSASignaturePadding.Pkcs1));
+
+ invalidName = new HashAlgorithmName("");
AssertExtensions.Throws("hashAlgorithm", () => SignData(rsa, new byte[1], invalidName, RSASignaturePadding.Pkcs1));
AssertExtensions.Throws("hashAlgorithm", () => SignHash(rsa, new byte[1], invalidName, RSASignaturePadding.Pkcs1));
AssertExtensions.Throws("hashAlgorithm", () => VerifyData(rsa, new byte[1], new byte[1], invalidName, RSASignaturePadding.Pkcs1));
diff --git a/src/libraries/System.ComponentModel.TypeConverter/src/Resources/Strings.resx b/src/libraries/System.ComponentModel.TypeConverter/src/Resources/Strings.resx
index e9dd12b50616dd..f607a8a2fe91cd 100644
--- a/src/libraries/System.ComponentModel.TypeConverter/src/Resources/Strings.resx
+++ b/src/libraries/System.ComponentModel.TypeConverter/src/Resources/Strings.resx
@@ -193,9 +193,6 @@
The specified character value is not allowed for this property.
-
- The Mask value cannot be null or empty.
-
The specified mask contains invalid characters.
@@ -253,4 +250,4 @@
BinaryFormatter serialization is obsolete and should not be used. See https://aka.ms/binaryformatter for more information.
-
\ No newline at end of file
+
diff --git a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/MaskedTextProvider.cs b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/MaskedTextProvider.cs
index 16ebdaf6ab3008..5810df7258e5fc 100644
--- a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/MaskedTextProvider.cs
+++ b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/MaskedTextProvider.cs
@@ -227,10 +227,7 @@ public MaskedTextProvider(string mask, CultureInfo? culture, char passwordChar,
///
public MaskedTextProvider(string mask, CultureInfo? culture, bool allowPromptAsInput, char promptChar, char passwordChar, bool restrictToAscii)
{
- if (string.IsNullOrEmpty(mask))
- {
- throw new ArgumentException(SR.MaskedTextProviderMaskNullOrEmpty, nameof(mask));
- }
+ ArgumentException.ThrowIfNullOrEmpty(mask);
foreach (char c in mask)
{
diff --git a/src/libraries/System.Diagnostics.Process/src/Resources/Strings.resx b/src/libraries/System.Diagnostics.Process/src/Resources/Strings.resx
index 2584ee5909a03f..ddbeed29f973ac 100644
--- a/src/libraries/System.Diagnostics.Process/src/Resources/Strings.resx
+++ b/src/libraries/System.Diagnostics.Process/src/Resources/Strings.resx
@@ -215,9 +215,6 @@
An async read operation has already been started on the stream.
-
- Invalid value '{1}' for parameter '{0}'.
-
Cannot load Category Help data because an invalid index '{0}' was read from the registry.
@@ -335,4 +332,4 @@
sysctl {0} failed with {1} error.
-
\ No newline at end of file
+
diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.cs
index 85525bbe3e8a59..7a776feba46dc6 100644
--- a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.cs
+++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.cs
@@ -10,11 +10,7 @@ internal static partial class ProcessManager
/// true if the machine is remote; false if it's local.
public static bool IsRemoteMachine(string machineName)
{
- if (machineName == null)
- throw new ArgumentNullException(nameof(machineName));
-
- if (machineName.Length == 0)
- throw new ArgumentException(SR.Format(SR.InvalidParameter, nameof(machineName), machineName));
+ ArgumentException.ThrowIfNullOrEmpty(machineName);
return IsRemoteMachineCore(machineName);
}
diff --git a/src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs b/src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs
index 18406af45353f4..b9d70837e3d168 100644
--- a/src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs
+++ b/src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs
@@ -1147,7 +1147,7 @@ public void GetProcesseses_NullMachineName_ThrowsArgumentNullException()
[Fact]
public void GetProcesses_EmptyMachineName_ThrowsArgumentException()
{
- AssertExtensions.Throws(null, () => Process.GetProcesses(""));
+ AssertExtensions.Throws("machineName", () => Process.GetProcesses(""));
}
[Fact]
@@ -1292,7 +1292,7 @@ public void GetProcessesByName_NullMachineName_ThrowsArgumentNullException()
public void GetProcessesByName_EmptyMachineName_ThrowsArgumentException()
{
Process currentProcess = Process.GetCurrentProcess();
- AssertExtensions.Throws(null, () => Process.GetProcessesByName(currentProcess.ProcessName, ""));
+ AssertExtensions.Throws("machineName", () => Process.GetProcessesByName(currentProcess.ProcessName, ""));
}
[Fact]
diff --git a/src/libraries/System.Diagnostics.TextWriterTraceListener/src/Resources/Strings.resx b/src/libraries/System.Diagnostics.TextWriterTraceListener/src/Resources/Strings.resx
index 12b248f4ddec28..b994dce1b5ab60 100644
--- a/src/libraries/System.Diagnostics.TextWriterTraceListener/src/Resources/Strings.resx
+++ b/src/libraries/System.Diagnostics.TextWriterTraceListener/src/Resources/Strings.resx
@@ -1,4 +1,5 @@
-
+
+
@@ -57,10 +58,7 @@
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
- '{0}' can not be empty string.
-
Trace
-
\ No newline at end of file
+
diff --git a/src/libraries/System.Diagnostics.TextWriterTraceListener/src/System/Diagnostics/DelimitedListTraceListener.cs b/src/libraries/System.Diagnostics.TextWriterTraceListener/src/System/Diagnostics/DelimitedListTraceListener.cs
index 6c399ae77bc405..52454f94c69068 100644
--- a/src/libraries/System.Diagnostics.TextWriterTraceListener/src/System/Diagnostics/DelimitedListTraceListener.cs
+++ b/src/libraries/System.Diagnostics.TextWriterTraceListener/src/System/Diagnostics/DelimitedListTraceListener.cs
@@ -63,11 +63,7 @@ public string Delimiter
}
set
{
- if (value == null)
- throw new ArgumentNullException(nameof(Delimiter));
-
- if (value.Length == 0)
- throw new ArgumentException(SR.Format(SR.Generic_ArgCantBeEmptyString, nameof(Delimiter)));
+ ArgumentException.ThrowIfNullOrEmpty(value, nameof(Delimiter));
lock (this)
{
diff --git a/src/libraries/System.Diagnostics.TextWriterTraceListener/tests/CtorsDelimiterTests.cs b/src/libraries/System.Diagnostics.TextWriterTraceListener/tests/CtorsDelimiterTests.cs
index f7620b442c5c19..352d0d1a6b29cb 100644
--- a/src/libraries/System.Diagnostics.TextWriterTraceListener/tests/CtorsDelimiterTests.cs
+++ b/src/libraries/System.Diagnostics.TextWriterTraceListener/tests/CtorsDelimiterTests.cs
@@ -90,8 +90,8 @@ public static void TestDelimiterProperty()
{
var target = new DelimitedListTraceListener(FileStream.Null);
Assert.Equal(DefaultDelimiter, target.Delimiter);
- Assert.Throws(() => target.Delimiter = null);
- AssertExtensions.Throws(null, () => target.Delimiter = string.Empty);
+ AssertExtensions.Throws("Delimiter", () => target.Delimiter = null);
+ AssertExtensions.Throws("Delimiter", () => target.Delimiter = string.Empty);
}
[Fact]
diff --git a/src/libraries/System.Diagnostics.TraceSource/src/Resources/Strings.resx b/src/libraries/System.Diagnostics.TraceSource/src/Resources/Strings.resx
index 8b4f1d87314133..4062db3292bae6 100644
--- a/src/libraries/System.Diagnostics.TraceSource/src/Resources/Strings.resx
+++ b/src/libraries/System.Diagnostics.TraceSource/src/Resources/Strings.resx
@@ -1,4 +1,5 @@
-
+
+
@@ -87,7 +88,4 @@
Attempted to set {0} to a value that is too high. Setting level to TraceLevel.Verbose
-
- Argument {0} cannot be null or zero-length.
-
-
\ No newline at end of file
+
diff --git a/src/libraries/System.Diagnostics.TraceSource/src/System/Diagnostics/SwitchAttribute.cs b/src/libraries/System.Diagnostics.TraceSource/src/System/Diagnostics/SwitchAttribute.cs
index 4b474c82442af1..18b00fdf83f638 100644
--- a/src/libraries/System.Diagnostics.TraceSource/src/System/Diagnostics/SwitchAttribute.cs
+++ b/src/libraries/System.Diagnostics.TraceSource/src/System/Diagnostics/SwitchAttribute.cs
@@ -26,10 +26,7 @@ public string SwitchName
[MemberNotNull(nameof(_name))]
set
{
- if (value == null)
- throw new ArgumentNullException(nameof(value));
- if (value.Length == 0)
- throw new ArgumentException(SR.Format(SR.InvalidNullEmptyArgument, nameof(value)), nameof(value));
+ ArgumentException.ThrowIfNullOrEmpty(value);
_name = value;
}
diff --git a/src/libraries/System.Diagnostics.TraceSource/src/System/Diagnostics/TraceSource.cs b/src/libraries/System.Diagnostics.TraceSource/src/System/Diagnostics/TraceSource.cs
index aa786154cbb567..4aedca7d878f59 100644
--- a/src/libraries/System.Diagnostics.TraceSource/src/System/Diagnostics/TraceSource.cs
+++ b/src/libraries/System.Diagnostics.TraceSource/src/System/Diagnostics/TraceSource.cs
@@ -28,10 +28,7 @@ public TraceSource(string name)
public TraceSource(string name, SourceLevels defaultLevel)
{
- if (name == null)
- throw new ArgumentNullException(nameof(name));
- if (name.Length == 0)
- throw new ArgumentException(SR.Format(SR.InvalidNullEmptyArgument, nameof(name)), nameof(name));
+ ArgumentException.ThrowIfNullOrEmpty(name);
_sourceName = name;
_switchLevel = defaultLevel;
diff --git a/src/libraries/System.IO.FileSystem.AccessControl/src/Resources/Strings.resx b/src/libraries/System.IO.FileSystem.AccessControl/src/Resources/Strings.resx
index 5b24a6296c36d0..60ea3e762eb475 100644
--- a/src/libraries/System.IO.FileSystem.AccessControl/src/Resources/Strings.resx
+++ b/src/libraries/System.IO.FileSystem.AccessControl/src/Resources/Strings.resx
@@ -1,3 +1,4 @@
+