Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal MethodInvoker(RuntimeConstructorInfo constructor)

public static MethodInvoker Create(MethodBase method)
{
ArgumentNullException.ThrowIfNull(method, nameof(method));
ArgumentNullException.ThrowIfNull(method);

if (method is RuntimeMethodInfo rmi)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ internal static unsafe void PtrToStructureImpl(IntPtr ptr, object structure)
public static unsafe void DestroyStructure(IntPtr ptr, Type structuretype)
{
ArgumentNullException.ThrowIfNull(ptr);
ArgumentNullException.ThrowIfNull(structuretype, nameof(structuretype));
ArgumentNullException.ThrowIfNull(structuretype);

RuntimeTypeHandle structureTypeHandle = structuretype.TypeHandle;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ internal static class NonCapturingTimer
{
public static Timer Create(TimerCallback callback, object state, TimeSpan dueTime, TimeSpan period)
{
if (callback is null)
{
throw new ArgumentNullException(nameof(callback));
}
ArgumentNullException.ThrowIfNull(callback);

// Don't capture the current ExecutionContext and its AsyncLocals onto the timer
bool restoreFlow = false;
Expand Down
7 changes: 0 additions & 7 deletions src/libraries/Common/src/System/CodeDom/CodeTypeReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,7 @@ public CodeTypeReference()

public CodeTypeReference(Type type)
{
#if NET
ArgumentNullException.ThrowIfNull(type);
#else
if (type is null)
{
throw new ArgumentNullException(nameof(type));
}
#endif

if (type.IsArray)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,7 @@ public CodeTypeReference this[int index]

public void AddRange(CodeTypeReference[] value)
{
#if NET
ArgumentNullException.ThrowIfNull(value);
#else
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
#endif

for (int i = 0; i < value.Length; i++)
{
Expand All @@ -58,14 +51,7 @@ public void AddRange(CodeTypeReference[] value)

public void AddRange(CodeTypeReferenceCollection value)
{
#if NET
ArgumentNullException.ThrowIfNull(value);
#else
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
#endif

int currentCount = value.Count;
for (int i = 0; i < currentCount; i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,8 @@ public static void Registration_TypeExportConventionOverridden(Type type)

public static void Registration_MemberExportConventionOverridden(Type type, MemberInfo member)
{
if (type is null)
{
throw new ArgumentNullException(nameof(type));
}
if (member is null)
{
throw new ArgumentNullException(nameof(member));
}
ArgumentNullException.ThrowIfNull(type);
ArgumentNullException.ThrowIfNull(member);

if (CompositionTraceSource.CanWriteWarning)
{
Expand All @@ -54,14 +48,8 @@ public static void Registration_MemberExportConventionOverridden(Type type, Memb

public static void Registration_MemberImportConventionOverridden(Type type, MemberInfo member)
{
if (type is null)
{
throw new ArgumentNullException(nameof(type));
}
if (member is null)
{
throw new ArgumentNullException(nameof(member));
}
ArgumentNullException.ThrowIfNull(type);
ArgumentNullException.ThrowIfNull(member);

if (CompositionTraceSource.CanWriteWarning)
{
Expand All @@ -73,14 +61,8 @@ public static void Registration_MemberImportConventionOverridden(Type type, Memb

public static void Registration_OnSatisfiedImportNotificationOverridden(Type type, MemberInfo member)
{
if (type is null)
{
throw new ArgumentNullException(nameof(type));
}
if (member is null)
{
throw new ArgumentNullException(nameof(member));
}
ArgumentNullException.ThrowIfNull(type);
ArgumentNullException.ThrowIfNull(member);

if (CompositionTraceSource.CanWriteWarning)
{
Expand All @@ -92,10 +74,7 @@ public static void Registration_OnSatisfiedImportNotificationOverridden(Type typ

public static void Registration_PartCreationConventionOverridden(Type type)
{
if (type is null)
{
throw new ArgumentNullException(nameof(type));
}
ArgumentNullException.ThrowIfNull(type);

if (CompositionTraceSource.CanWriteWarning)
{
Expand All @@ -107,14 +86,8 @@ public static void Registration_PartCreationConventionOverridden(Type type)

public static void Registration_MemberImportConventionMatchedTwice(Type type, MemberInfo member)
{
if (type is null)
{
throw new ArgumentNullException(nameof(type));
}
if (member is null)
{
throw new ArgumentNullException(nameof(member));
}
ArgumentNullException.ThrowIfNull(type);
ArgumentNullException.ThrowIfNull(member);

if (CompositionTraceSource.CanWriteWarning)
{
Expand All @@ -126,10 +99,7 @@ public static void Registration_MemberImportConventionMatchedTwice(Type type, Me

public static void Registration_PartMetadataConventionOverridden(Type type)
{
if (type is null)
{
throw new ArgumentNullException(nameof(type));
}
ArgumentNullException.ThrowIfNull(type);

if (CompositionTraceSource.CanWriteWarning)
{
Expand All @@ -141,14 +111,8 @@ public static void Registration_PartMetadataConventionOverridden(Type type)

public static void Registration_ParameterImportConventionOverridden(ParameterInfo parameter, ConstructorInfo constructor)
{
if (parameter is null)
{
throw new ArgumentNullException(nameof(parameter));
}
if (constructor is null)
{
throw new ArgumentNullException(nameof(constructor));
}
ArgumentNullException.ThrowIfNull(parameter);
ArgumentNullException.ThrowIfNull(constructor);

if (CompositionTraceSource.CanWriteWarning)
{
Expand Down
27 changes: 27 additions & 0 deletions src/libraries/Common/src/System/ExceptionPolyfills.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;

namespace System
{
/// <summary>Provides downlevel polyfills for static methods on Exception-derived types.</summary>
internal static class ExceptionPolyfills
{
extension(ArgumentNullException)
{
public static void ThrowIfNull([NotNull] object? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
{
if (argument is null)
{
ThrowArgumentNullException(paramName);
}
}
}

[DoesNotReturn]
private static void ThrowArgumentNullException(string? paramName) =>
throw new ArgumentNullException(paramName);
}
}
5 changes: 1 addition & 4 deletions src/libraries/Common/src/System/IO/ReadOnlyMemoryStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,7 @@ protected override void Dispose(bool disposing)
#if NETFRAMEWORK || NETSTANDARD2_0
private static void ValidateBufferArguments(byte[] buffer, int offset, int count)
{
if (buffer is null)
{
throw new ArgumentNullException(nameof(buffer));
}
ArgumentNullException.ThrowIfNull(buffer);

if (offset < 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ internal static partial class StreamHelpers
/// <summary>Validate the arguments to CopyTo, as would Stream.CopyTo.</summary>
public static void ValidateCopyToArgs(Stream source, Stream destination, int bufferSize)
{
if (destination is null)
{
throw new ArgumentNullException(nameof(destination));
}
ArgumentNullException.ThrowIfNull(destination);

if (bufferSize <= 0)
{
Expand Down
30 changes: 6 additions & 24 deletions src/libraries/Common/src/System/Resources/ResourceWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ public sealed partial class
ResourceWriter(string fileName)
#endif
{
if (fileName is null)
{
throw new ArgumentNullException(nameof(fileName));
}
ArgumentNullException.ThrowIfNull(fileName);

_output = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None);
_resourceList = new SortedDictionary<string, object?>(FastResourceComparer.Default);
Expand All @@ -65,10 +62,7 @@ public sealed partial class
ResourceWriter(Stream stream)
#endif
{
if (stream is null)
{
throw new ArgumentNullException(nameof(stream));
}
ArgumentNullException.ThrowIfNull(stream);

if (!stream.CanWrite)
{
Expand All @@ -85,10 +79,7 @@ public sealed partial class
//
public void AddResource(string name, string? value)
{
if (name is null)
{
throw new ArgumentNullException(nameof(name));
}
ArgumentNullException.ThrowIfNull(name);

if (_resourceList == null)
{
Expand All @@ -105,10 +96,7 @@ public void AddResource(string name, string? value)
//
public void AddResource(string name, object? value)
{
if (name is null)
{
throw new ArgumentNullException(nameof(name));
}
ArgumentNullException.ThrowIfNull(name);

if (_resourceList == null)
{
Expand All @@ -134,10 +122,7 @@ public void AddResource(string name, object? value)
//
public void AddResource(string name, Stream? value, bool closeAfterWrite = false)
{
if (name is null)
{
throw new ArgumentNullException(nameof(name));
}
ArgumentNullException.ThrowIfNull(name);

if (_resourceList == null)
{
Expand Down Expand Up @@ -174,10 +159,7 @@ private void AddResourceInternal(string name, Stream? value, bool closeAfterWrit
//
public void AddResource(string name, byte[]? value)
{
if (name is null)
{
throw new ArgumentNullException(nameof(name));
}
ArgumentNullException.ThrowIfNull(name);

if (_resourceList == null)
{
Expand Down
28 changes: 0 additions & 28 deletions src/libraries/Common/src/System/Security/Cryptography/AesGcm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,24 +156,10 @@ private partial void EncryptCore(
/// <exception cref="CryptographicException">The encryption operation failed.</exception>
public void Encrypt(byte[] nonce, byte[] plaintext, byte[] ciphertext, byte[] tag, byte[]? associatedData = null)
{
#if NET
ArgumentNullException.ThrowIfNull(nonce);
ArgumentNullException.ThrowIfNull(plaintext);
ArgumentNullException.ThrowIfNull(ciphertext);
ArgumentNullException.ThrowIfNull(tag);
#else
if (nonce is null)
throw new ArgumentNullException(nameof(nonce));

if (plaintext is null)
throw new ArgumentNullException(nameof(plaintext));

if (ciphertext is null)
throw new ArgumentNullException(nameof(ciphertext));

if (tag is null)
throw new ArgumentNullException(nameof(tag));
#endif

Encrypt((ReadOnlySpan<byte>)nonce, plaintext, ciphertext, tag, associatedData);
}
Expand Down Expand Up @@ -249,24 +235,10 @@ public void Encrypt(
/// <exception cref="AuthenticationTagMismatchException">The tag value could not be verified.</exception>
public void Decrypt(byte[] nonce, byte[] ciphertext, byte[] tag, byte[] plaintext, byte[]? associatedData = null)
{
#if NET
ArgumentNullException.ThrowIfNull(nonce);
ArgumentNullException.ThrowIfNull(ciphertext);
ArgumentNullException.ThrowIfNull(tag);
ArgumentNullException.ThrowIfNull(plaintext);
#else
if (nonce is null)
throw new ArgumentNullException(nameof(nonce));

if (ciphertext is null)
throw new ArgumentNullException(nameof(ciphertext));

if (tag is null)
throw new ArgumentNullException(nameof(tag));

if (plaintext is null)
throw new ArgumentNullException(nameof(plaintext));
#endif

Decrypt((ReadOnlySpan<byte>)nonce, ciphertext, tag, plaintext, associatedData);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#pragma warning disable CA1510

namespace System.Security.Cryptography.Asn1
{
internal partial struct AttributeAsn
{
public AttributeAsn(AsnEncodedData attribute)
{
#if NET
ArgumentNullException.ThrowIfNull(attribute);
#else
if (attribute is null)
{
throw new ArgumentNullException(nameof(attribute));
}
#endif

AttrType = attribute.Oid!.Value!;
AttrValues = new[] { new ReadOnlyMemory<byte>(attribute.RawData) };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,7 @@ internal partial struct X509ExtensionAsn
{
public X509ExtensionAsn(X509Extension extension)
{
#if NET
ArgumentNullException.ThrowIfNull(extension);
#else
if (extension is null)
{
throw new ArgumentNullException(nameof(extension));
}
#endif

ExtnId = extension.Oid!.Value!;
Critical = extension.Critical;
Expand Down
Loading
Loading