Skip to content
Closed
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

<ItemGroup>
<Compile Include="System.ObjectModel.Forwards.cs" />
<Compile Include="System\ThrowHelper.cs" />
<Compile Include="System\Collections\CollectionHelpers.cs" />
<Compile Include="System\Collections\Generic\DebugView.cs" />
<Compile Include="System\Collections\Specialized\INotifyCollectionChanged.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ public TItem this[TKey key]

public bool Contains(TKey key)
{
ArgumentNullException.ThrowIfNull(key);
if (key == null)
{
ThrowHelper.ThrowArgumentNullException(nameof(key));
}

if (dict != null)
{
Expand All @@ -91,7 +94,10 @@ public bool Contains(TKey key)

public bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TItem item)
{
ArgumentNullException.ThrowIfNull(key);
if (key == null)
{
ThrowHelper.ThrowArgumentNullException(nameof(key));
}

if (dict != null)
{
Expand Down Expand Up @@ -131,7 +137,10 @@ private bool ContainsItem(TItem item)

public bool Remove(TKey key)
{
ArgumentNullException.ThrowIfNull(key);
if (key == null)
{
ThrowHelper.ThrowArgumentNullException(nameof(key));
}

if (dict != null)
{
Expand Down
14 changes: 14 additions & 0 deletions src/libraries/System.ObjectModel/src/System/ThrowHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// 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;

namespace System
{
internal static class ThrowHelper
{
[DoesNotReturn]
public static void ThrowArgumentNullException(string? paramName) =>
throw new ArgumentNullException(paramName);
}
}