diff --git a/ARMeilleure/Common/AddressTable.cs b/ARMeilleure/Common/AddressTable.cs
index 7cb83fdd20..9db2d00de2 100644
--- a/ARMeilleure/Common/AddressTable.cs
+++ b/ARMeilleure/Common/AddressTable.cs
@@ -80,10 +80,7 @@ namespace ARMeilleure.Common
{
get
{
- if (_disposed)
- {
- throw new ObjectDisposedException(null);
- }
+ ObjectDisposedException.ThrowIf(_disposed, this);
lock (_pages)
{
@@ -100,10 +97,7 @@ namespace ARMeilleure.Common
/// Length of is less than 2
public AddressTable(Level[] levels)
{
- if (levels == null)
- {
- throw new ArgumentNullException(nameof(levels));
- }
+ ArgumentNullException.ThrowIfNull(levels);
if (levels.Length < 2)
{
@@ -141,10 +135,7 @@ namespace ARMeilleure.Common
/// is not mapped
public ref TEntry GetValue(ulong address)
{
- if (_disposed)
- {
- throw new ObjectDisposedException(null);
- }
+ ObjectDisposedException.ThrowIf(_disposed, this);
if (!IsValid(address))
{
diff --git a/ARMeilleure/Common/Counter.cs b/ARMeilleure/Common/Counter.cs
index 4b0627c1a7..d7210d1591 100644
--- a/ARMeilleure/Common/Counter.cs
+++ b/ARMeilleure/Common/Counter.cs
@@ -49,10 +49,7 @@ namespace ARMeilleure.Common
{
get
{
- if (_disposed)
- {
- throw new ObjectDisposedException(null);
- }
+ ObjectDisposedException.ThrowIf(_disposed, this);
return ref _countTable.GetValue(_index);
}
diff --git a/ARMeilleure/Common/EntryTable.cs b/ARMeilleure/Common/EntryTable.cs
index f3f3ce281a..6f20579799 100644
--- a/ARMeilleure/Common/EntryTable.cs
+++ b/ARMeilleure/Common/EntryTable.cs
@@ -53,10 +53,7 @@ namespace ARMeilleure.Common
/// instance was disposed
public int Allocate()
{
- if (_disposed)
- {
- throw new ObjectDisposedException(null);
- }
+ ObjectDisposedException.ThrowIf(_disposed, this);
lock (_allocated)
{
@@ -83,10 +80,7 @@ namespace ARMeilleure.Common
/// instance was disposed
public void Free(int index)
{
- if (_disposed)
- {
- throw new ObjectDisposedException(null);
- }
+ ObjectDisposedException.ThrowIf(_disposed, this);
lock (_allocated)
{
@@ -108,10 +102,7 @@ namespace ARMeilleure.Common
/// Entry at is not allocated
public ref TEntry GetValue(int index)
{
- if (_disposed)
- {
- throw new ObjectDisposedException(null);
- }
+ ObjectDisposedException.ThrowIf(_disposed, this);
lock (_allocated)
{
diff --git a/ARMeilleure/IntermediateRepresentation/BasicBlock.cs b/ARMeilleure/IntermediateRepresentation/BasicBlock.cs
index 7cee52e582..07bd8b672d 100644
--- a/ARMeilleure/IntermediateRepresentation/BasicBlock.cs
+++ b/ARMeilleure/IntermediateRepresentation/BasicBlock.cs
@@ -48,10 +48,7 @@ namespace ARMeilleure.IntermediateRepresentation
public void AddSuccessor(BasicBlock block)
{
- if (block == null)
- {
- ThrowNull(nameof(block));
- }
+ ArgumentNullException.ThrowIfNull(block);
if ((uint)_succCount + 1 > MaxSuccessors)
{
@@ -100,10 +97,7 @@ namespace ARMeilleure.IntermediateRepresentation
public void SetSuccessor(int index, BasicBlock block)
{
- if (block == null)
- {
- ThrowNull(nameof(block));
- }
+ ArgumentNullException.ThrowIfNull(block);
if ((uint)index >= (uint)_succCount)
{
@@ -144,7 +138,6 @@ namespace ARMeilleure.IntermediateRepresentation
}
}
- private static void ThrowNull(string name) => throw new ArgumentNullException(name);
private static void ThrowOutOfRange(string name) => throw new ArgumentOutOfRangeException(name);
private static void ThrowSuccessorOverflow() => throw new OverflowException($"BasicBlock can only have {MaxSuccessors} successors.");
diff --git a/ARMeilleure/Translation/DelegateHelper.cs b/ARMeilleure/Translation/DelegateHelper.cs
index f021d1160a..43a39bab0a 100644
--- a/ARMeilleure/Translation/DelegateHelper.cs
+++ b/ARMeilleure/Translation/DelegateHelper.cs
@@ -25,10 +25,7 @@ namespace ARMeilleure.Translation
public static Delegate GetDelegate(MethodInfo info)
{
- if (info == null)
- {
- throw new ArgumentNullException(nameof(info));
- }
+ ArgumentNullException.ThrowIfNull(info);
Type[] parameters = info.GetParameters().Select(pI => pI.ParameterType).ToArray();
Type returnType = info.ReturnType;
diff --git a/ARMeilleure/Translation/Delegates.cs b/ARMeilleure/Translation/Delegates.cs
index fef1f4ef70..9d3fdc1722 100644
--- a/ARMeilleure/Translation/Delegates.cs
+++ b/ARMeilleure/Translation/Delegates.cs
@@ -35,10 +35,7 @@ namespace ARMeilleure.Translation
public static IntPtr GetDelegateFuncPtr(MethodInfo info)
{
- if (info == null)
- {
- throw new ArgumentNullException(nameof(info));
- }
+ ArgumentNullException.ThrowIfNull(info);
string key = GetKey(info);
@@ -52,10 +49,7 @@ namespace ARMeilleure.Translation
public static int GetDelegateIndex(MethodInfo info)
{
- if (info == null)
- {
- throw new ArgumentNullException(nameof(info));
- }
+ ArgumentNullException.ThrowIfNull(info);
string key = GetKey(info);
diff --git a/ARMeilleure/Translation/IntervalTree.cs b/ARMeilleure/Translation/IntervalTree.cs
index 79662bc98f..9af01bea03 100644
--- a/ARMeilleure/Translation/IntervalTree.cs
+++ b/ARMeilleure/Translation/IntervalTree.cs
@@ -67,10 +67,7 @@ namespace ARMeilleure.Translation
/// True if the value was added, false if the start key was already in the dictionary
public bool AddOrUpdate(K start, K end, V value, Func updateFactoryCallback)
{
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
+ ArgumentNullException.ThrowIfNull(value);
return BSTInsert(start, end, value, updateFactoryCallback, out IntervalTreeNode node);
}
@@ -85,10 +82,7 @@ namespace ARMeilleure.Translation
/// if is not yet on the tree, or the existing value otherwise
public V GetOrAdd(K start, K end, V value)
{
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
+ ArgumentNullException.ThrowIfNull(value);
BSTInsert(start, end, value, null, out IntervalTreeNode node);
return node.Value;
@@ -152,10 +146,7 @@ namespace ARMeilleure.Translation
/// Node reference in the tree
private IntervalTreeNode GetNode(K key)
{
- if (key == null)
- {
- throw new ArgumentNullException(nameof(key));
- }
+ ArgumentNullException.ThrowIfNull(key);
IntervalTreeNode node = _root;
while (node != null)
diff --git a/ARMeilleure/Translation/TranslatorStubs.cs b/ARMeilleure/Translation/TranslatorStubs.cs
index 4ad6c2f233..67d2bba8e5 100644
--- a/ARMeilleure/Translation/TranslatorStubs.cs
+++ b/ARMeilleure/Translation/TranslatorStubs.cs
@@ -30,10 +30,7 @@ namespace ARMeilleure.Translation
{
get
{
- if (_disposed)
- {
- throw new ObjectDisposedException(null);
- }
+ ObjectDisposedException.ThrowIf(_disposed, this);
return _dispatchStub.Value;
}
@@ -47,10 +44,7 @@ namespace ARMeilleure.Translation
{
get
{
- if (_disposed)
- {
- throw new ObjectDisposedException(null);
- }
+ ObjectDisposedException.ThrowIf(_disposed, this);
return _slowDispatchStub.Value;
}
@@ -64,10 +58,7 @@ namespace ARMeilleure.Translation
{
get
{
- if (_disposed)
- {
- throw new ObjectDisposedException(null);
- }
+ ObjectDisposedException.ThrowIf(_disposed, this);
return _dispatchLoop.Value;
}
@@ -81,7 +72,9 @@ namespace ARMeilleure.Translation
/// is null
public TranslatorStubs(Translator translator)
{
- _translator = translator ?? throw new ArgumentNullException(nameof(translator));
+ ArgumentNullException.ThrowIfNull(translator);
+
+ _translator = translator;
_dispatchStub = new(GenerateDispatchStub, isThreadSafe: true);
_dispatchLoop = new(GenerateDispatchLoop, isThreadSafe: true);
}
diff --git a/Ryujinx.Common/Collections/IntervalTree.cs b/Ryujinx.Common/Collections/IntervalTree.cs
index c829cabae2..b5188cc7eb 100644
--- a/Ryujinx.Common/Collections/IntervalTree.cs
+++ b/Ryujinx.Common/Collections/IntervalTree.cs
@@ -24,10 +24,7 @@ namespace Ryujinx.Common.Collections
/// is null
public int Get(K key, ref V[] overlaps)
{
- if (key == null)
- {
- throw new ArgumentNullException(nameof(key));
- }
+ ArgumentNullException.ThrowIfNull(key);
IntervalTreeNode node = GetNode(key);
@@ -61,15 +58,8 @@ namespace Ryujinx.Common.Collections
/// or is null
public int Get(K start, K end, ref V[] overlaps, int overlapCount = 0)
{
- if (start == null)
- {
- throw new ArgumentNullException(nameof(start));
- }
-
- if (end == null)
- {
- throw new ArgumentNullException(nameof(end));
- }
+ ArgumentNullException.ThrowIfNull(start);
+ ArgumentNullException.ThrowIfNull(end);
GetValues(Root, start, end, ref overlaps, ref overlapCount);
@@ -85,20 +75,9 @@ namespace Ryujinx.Common.Collections
/// , or are null
public void Add(K start, K end, V value)
{
- if (start == null)
- {
- throw new ArgumentNullException(nameof(start));
- }
-
- if (end == null)
- {
- throw new ArgumentNullException(nameof(end));
- }
-
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
+ ArgumentNullException.ThrowIfNull(start);
+ ArgumentNullException.ThrowIfNull(end);
+ ArgumentNullException.ThrowIfNull(value);
Insert(start, end, value);
}
@@ -112,10 +91,7 @@ namespace Ryujinx.Common.Collections
/// Number of deleted values
public int Remove(K key, V value)
{
- if (key == null)
- {
- throw new ArgumentNullException(nameof(key));
- }
+ ArgumentNullException.ThrowIfNull(key);
int removed = Delete(key, value);
@@ -168,10 +144,7 @@ namespace Ryujinx.Common.Collections
/// is null
private IntervalTreeNode GetNode(K key)
{
- if (key == null)
- {
- throw new ArgumentNullException(nameof(key));
- }
+ ArgumentNullException.ThrowIfNull(key);
IntervalTreeNode node = Root;
while (node != null)
@@ -462,10 +435,8 @@ namespace Ryujinx.Common.Collections
public bool ContainsKey(K key)
{
- if (key == null)
- {
- throw new ArgumentNullException(nameof(key));
- }
+ ArgumentNullException.ThrowIfNull(key);
+
return GetNode(key) != null;
}
}
diff --git a/Ryujinx.Common/Collections/IntrusiveRedBlackTree.cs b/Ryujinx.Common/Collections/IntrusiveRedBlackTree.cs
index 970cab87c6..0063d91e40 100644
--- a/Ryujinx.Common/Collections/IntrusiveRedBlackTree.cs
+++ b/Ryujinx.Common/Collections/IntrusiveRedBlackTree.cs
@@ -17,10 +17,7 @@ namespace Ryujinx.Common.Collections
/// is null
public void Add(T node)
{
- if (node == null)
- {
- throw new ArgumentNullException(nameof(node));
- }
+ ArgumentNullException.ThrowIfNull(node);
Insert(node);
}
@@ -32,10 +29,8 @@ namespace Ryujinx.Common.Collections
/// is null
public void Remove(T node)
{
- if (node == null)
- {
- throw new ArgumentNullException(nameof(node));
- }
+ ArgumentNullException.ThrowIfNull(node);
+
if (Delete(node) != null)
{
Count--;
@@ -50,10 +45,7 @@ namespace Ryujinx.Common.Collections
/// is null
public T GetNode(T searchNode)
{
- if (searchNode == null)
- {
- throw new ArgumentNullException(nameof(searchNode));
- }
+ ArgumentNullException.ThrowIfNull(searchNode);
T node = Root;
while (node != null)
diff --git a/Ryujinx.Common/Collections/IntrusiveRedBlackTreeImpl.cs b/Ryujinx.Common/Collections/IntrusiveRedBlackTreeImpl.cs
index 267aeec31a..bcb2e2a239 100644
--- a/Ryujinx.Common/Collections/IntrusiveRedBlackTreeImpl.cs
+++ b/Ryujinx.Common/Collections/IntrusiveRedBlackTreeImpl.cs
@@ -92,10 +92,8 @@ namespace Ryujinx.Common.Collections
/// is null
protected static T Minimum(T node)
{
- if (node == null)
- {
- throw new ArgumentNullException(nameof(node));
- }
+ ArgumentNullException.ThrowIfNull(node);
+
T tmp = node;
while (tmp.Left != null)
{
diff --git a/Ryujinx.Common/Collections/TreeDictionary.cs b/Ryujinx.Common/Collections/TreeDictionary.cs
index a5a3b8189f..d118a30cc4 100644
--- a/Ryujinx.Common/Collections/TreeDictionary.cs
+++ b/Ryujinx.Common/Collections/TreeDictionary.cs
@@ -22,10 +22,7 @@ namespace Ryujinx.Common.Collections
/// is null
public V Get(K key)
{
- if (key == null)
- {
- throw new ArgumentNullException(nameof(key));
- }
+ ArgumentNullException.ThrowIfNull(key);
Node node = GetNode(key);
@@ -47,14 +44,8 @@ namespace Ryujinx.Common.Collections
/// or are null
public void Add(K key, V value)
{
- if (key == null)
- {
- throw new ArgumentNullException(nameof(key));
- }
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
+ ArgumentNullException.ThrowIfNull(key);
+ ArgumentNullException.ThrowIfNull(value);
Insert(key, value);
}
@@ -66,10 +57,8 @@ namespace Ryujinx.Common.Collections
/// is null
public void Remove(K key)
{
- if (key == null)
- {
- throw new ArgumentNullException(nameof(key));
- }
+ ArgumentNullException.ThrowIfNull(key);
+
if (Delete(key) != null)
{
Count--;
@@ -217,10 +206,7 @@ namespace Ryujinx.Common.Collections
/// is null
private Node GetNode(K key)
{
- if (key == null)
- {
- throw new ArgumentNullException(nameof(key));
- }
+ ArgumentNullException.ThrowIfNull(key);
Node node = Root;
while (node != null)
@@ -370,10 +356,8 @@ namespace Ryujinx.Common.Collections
/// is null
private Node FloorNode(K key)
{
- if (key == null)
- {
- throw new ArgumentNullException(nameof(key));
- }
+ ArgumentNullException.ThrowIfNull(key);
+
Node tmp = Root;
while (tmp != null)
@@ -424,10 +408,8 @@ namespace Ryujinx.Common.Collections
/// is null
private Node CeilingNode(K key)
{
- if (key == null)
- {
- throw new ArgumentNullException(nameof(key));
- }
+ ArgumentNullException.ThrowIfNull(key);
+
Node tmp = Root;
while (tmp != null)
@@ -477,10 +459,8 @@ namespace Ryujinx.Common.Collections
// Method descriptions are not provided as they are already included as part of the interface.
public bool ContainsKey(K key)
{
- if (key == null)
- {
- throw new ArgumentNullException(nameof(key));
- }
+ ArgumentNullException.ThrowIfNull(key);
+
return GetNode(key) != null;
}
@@ -493,10 +473,8 @@ namespace Ryujinx.Common.Collections
public bool TryGetValue(K key, [MaybeNullWhen(false)] out V value)
{
- if (null == key)
- {
- throw new ArgumentNullException(nameof(key));
- }
+ ArgumentNullException.ThrowIfNull(key);
+
Node node = GetNode(key);
value = node != null ? node.Value : default;
return node != null;
@@ -504,10 +482,7 @@ namespace Ryujinx.Common.Collections
public void Add(KeyValuePair item)
{
- if (item.Key == null)
- {
- throw new ArgumentNullException(nameof(item.Key));
- }
+ ArgumentNullException.ThrowIfNull(item.Key);
Add(item.Key, item.Value);
}
diff --git a/Ryujinx.HLE/Switch.cs b/Ryujinx.HLE/Switch.cs
index de0f98e46a..46af68f493 100644
--- a/Ryujinx.HLE/Switch.cs
+++ b/Ryujinx.HLE/Switch.cs
@@ -32,20 +32,9 @@ namespace Ryujinx.HLE
public Switch(HLEConfiguration configuration)
{
- if (configuration.GpuRenderer == null)
- {
- throw new ArgumentNullException(nameof(configuration.GpuRenderer));
- }
-
- if (configuration.AudioDeviceDriver == null)
- {
- throw new ArgumentNullException(nameof(configuration.AudioDeviceDriver));
- }
-
- if (configuration.UserChannelPersistence == null)
- {
- throw new ArgumentNullException(nameof(configuration.UserChannelPersistence));
- }
+ ArgumentNullException.ThrowIfNull(configuration.GpuRenderer);
+ ArgumentNullException.ThrowIfNull(configuration.AudioDeviceDriver);
+ ArgumentNullException.ThrowIfNull(configuration.UserChannelPersistence);
Configuration = configuration;
FileSystem = Configuration.VirtualFileSystem;
diff --git a/Ryujinx.Memory/MemoryBlock.cs b/Ryujinx.Memory/MemoryBlock.cs
index 79a5cfe7c7..41e6224bbf 100644
--- a/Ryujinx.Memory/MemoryBlock.cs
+++ b/Ryujinx.Memory/MemoryBlock.cs
@@ -279,10 +279,7 @@ namespace Ryujinx.Memory
{
IntPtr ptr = _pointer;
- if (ptr == IntPtr.Zero)
- {
- ThrowObjectDisposed();
- }
+ ObjectDisposedException.ThrowIf(ptr == IntPtr.Zero, this);
int size = Unsafe.SizeOf();
@@ -312,10 +309,7 @@ namespace Ryujinx.Memory
{
IntPtr ptr = _pointer;
- if (ptr == IntPtr.Zero)
- {
- ThrowObjectDisposed();
- }
+ ObjectDisposedException.ThrowIf(ptr == IntPtr.Zero, this);
ulong endOffset = offset + size;
@@ -454,7 +448,6 @@ namespace Ryujinx.Memory
return true;
}
- private static void ThrowObjectDisposed() => throw new ObjectDisposedException(nameof(MemoryBlock));
private static void ThrowInvalidMemoryRegionException() => throw new InvalidMemoryRegionException();
}
}
diff --git a/Ryujinx.Memory/Tracking/RegionHandle.cs b/Ryujinx.Memory/Tracking/RegionHandle.cs
index affc84abb2..86c77abc33 100644
--- a/Ryujinx.Memory/Tracking/RegionHandle.cs
+++ b/Ryujinx.Memory/Tracking/RegionHandle.cs
@@ -411,10 +411,7 @@ namespace Ryujinx.Memory.Tracking
///
public void Dispose()
{
- if (_disposed)
- {
- throw new ObjectDisposedException(GetType().FullName);
- }
+ ObjectDisposedException.ThrowIf(_disposed, this);
_disposed = true;