From 0d3b82477ecbf7128340b6725a79413427c68748 Mon Sep 17 00:00:00 2001
From: Berkan Diler <berkan.diler1@ingka.ikea.com>
Date: Tue, 27 Dec 2022 20:27:11 +0100
Subject: [PATCH] Use new ArgumentNullException and ObjectDisposedException
 throw-helper API (#4163)

---
 ARMeilleure/Common/AddressTable.cs            | 15 +----
 ARMeilleure/Common/Counter.cs                 |  5 +-
 ARMeilleure/Common/EntryTable.cs              | 15 +----
 .../IntermediateRepresentation/BasicBlock.cs  | 11 +---
 ARMeilleure/Translation/DelegateHelper.cs     |  5 +-
 ARMeilleure/Translation/Delegates.cs          | 10 +---
 ARMeilleure/Translation/IntervalTree.cs       | 15 +----
 ARMeilleure/Translation/TranslatorStubs.cs    | 19 ++-----
 Ryujinx.Common/Collections/IntervalTree.cs    | 49 ++++-------------
 .../Collections/IntrusiveRedBlackTree.cs      | 16 ++----
 .../Collections/IntrusiveRedBlackTreeImpl.cs  |  6 +-
 Ryujinx.Common/Collections/TreeDictionary.cs  | 55 +++++--------------
 Ryujinx.HLE/Switch.cs                         | 17 +-----
 Ryujinx.Memory/MemoryBlock.cs                 | 11 +---
 Ryujinx.Memory/Tracking/RegionHandle.cs       |  5 +-
 15 files changed, 58 insertions(+), 196 deletions(-)

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
         /// <exception cref="ArgumentException">Length of <paramref name="levels"/> is less than 2</exception>
         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
         /// <exception cref="ArgumentException"><paramref name="address"/> is not mapped</exception>
         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
         /// <exception cref="ObjectDisposedException"><see cref="EntryTable{TEntry}"/> instance was disposed</exception>
         public int Allocate()
         {
-            if (_disposed)
-            {
-                throw new ObjectDisposedException(null);
-            }
+            ObjectDisposedException.ThrowIf(_disposed, this);
 
             lock (_allocated)
             {
@@ -83,10 +80,7 @@ namespace ARMeilleure.Common
         /// <exception cref="ObjectDisposedException"><see cref="EntryTable{TEntry}"/> instance was disposed</exception>
         public void Free(int index)
         {
-            if (_disposed)
-            {
-                throw new ObjectDisposedException(null);
-            }
+            ObjectDisposedException.ThrowIf(_disposed, this);
 
             lock (_allocated)
             {
@@ -108,10 +102,7 @@ namespace ARMeilleure.Common
         /// <exception cref="ArgumentException">Entry at <paramref name="index"/> is not allocated</exception>
         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
         /// <returns>True if the value was added, false if the start key was already in the dictionary</returns>
         public bool AddOrUpdate(K start, K end, V value, Func<K, V, V> updateFactoryCallback)
         {
-            if (value == null)
-            {
-                throw new ArgumentNullException(nameof(value));
-            }
+            ArgumentNullException.ThrowIfNull(value);
 
             return BSTInsert(start, end, value, updateFactoryCallback, out IntervalTreeNode<K, V> node);
         }
@@ -85,10 +82,7 @@ namespace ARMeilleure.Translation
         /// <returns><paramref name="value"/> if <paramref name="start"/> is not yet on the tree, or the existing value otherwise</returns>
         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<K, V> node);
             return node.Value;
@@ -152,10 +146,7 @@ namespace ARMeilleure.Translation
         /// <returns>Node reference in the tree</returns>
         private IntervalTreeNode<K, V> GetNode(K key)
         {
-            if (key == null)
-            {
-                throw new ArgumentNullException(nameof(key));
-            }
+            ArgumentNullException.ThrowIfNull(key);
 
             IntervalTreeNode<K, V> 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
         /// <exception cref="ArgumentNullException"><paramref name="translator"/> is null</exception>
         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
         /// <exception cref="ArgumentNullException"><paramref name="key"/> is null</exception>
         public int Get(K key, ref V[] overlaps)
         {
-            if (key == null)
-            {
-                throw new ArgumentNullException(nameof(key));
-            }
+            ArgumentNullException.ThrowIfNull(key);
 
             IntervalTreeNode<K, V> node = GetNode(key);
 
@@ -61,15 +58,8 @@ namespace Ryujinx.Common.Collections
         /// <exception cref="ArgumentNullException"><paramref name="start"/> or <paramref name="end"/> is null</exception>
         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
         /// <exception cref="ArgumentNullException"><paramref name="start"/>, <paramref name="end"/> or <paramref name="value"/> are null</exception>
         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
         /// <returns>Number of deleted values</returns>
         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
         /// <exception cref="ArgumentNullException"><paramref name="key"/> is null</exception>
         private IntervalTreeNode<K, V> GetNode(K key)
         {
-            if (key == null)
-            {
-                throw new ArgumentNullException(nameof(key));
-            }
+            ArgumentNullException.ThrowIfNull(key);
 
             IntervalTreeNode<K, V> 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
         /// <exception cref="ArgumentNullException"><paramref name="node"/> is null</exception>
         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
         /// <exception cref="ArgumentNullException"><paramref name="node"/> is null</exception>
         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
         /// <exception cref="ArgumentNullException"><paramref name="searchNode"/> is null</exception>
         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
         /// <exception cref="ArgumentNullException"><paramref name="node"/> is null</exception>
         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
         /// <exception cref="ArgumentNullException"><paramref name="key"/> is null</exception>
         public V Get(K key)
         {
-            if (key == null)
-            {
-                throw new ArgumentNullException(nameof(key));
-            }
+            ArgumentNullException.ThrowIfNull(key);
 
             Node<K, V> node = GetNode(key);
 
@@ -47,14 +44,8 @@ namespace Ryujinx.Common.Collections
         /// <exception cref="ArgumentNullException"><paramref name="key"/> or <paramref name="value"/> are null</exception>
         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
         /// <exception cref="ArgumentNullException"><paramref name="key"/> is null</exception>
         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
         /// <exception cref="ArgumentNullException"><paramref name="key"/> is null</exception>
         private Node<K, V> GetNode(K key)
         {
-            if (key == null)
-            {
-                throw new ArgumentNullException(nameof(key));
-            }
+            ArgumentNullException.ThrowIfNull(key);
 
             Node<K, V> node = Root;
             while (node != null)
@@ -370,10 +356,8 @@ namespace Ryujinx.Common.Collections
         /// <exception cref="ArgumentNullException"><paramref name="key"/> is null</exception>
         private Node<K, V> FloorNode(K key)
         {
-            if (key == null)
-            {
-                throw new ArgumentNullException(nameof(key));
-            }
+            ArgumentNullException.ThrowIfNull(key);
+
             Node<K, V> tmp = Root;
 
             while (tmp != null)
@@ -424,10 +408,8 @@ namespace Ryujinx.Common.Collections
         /// <exception cref="ArgumentNullException"><paramref name="key"/> is null</exception>
         private Node<K, V> CeilingNode(K key)
         {
-            if (key == null)
-            {
-                throw new ArgumentNullException(nameof(key));
-            }
+            ArgumentNullException.ThrowIfNull(key);
+
             Node<K, V> 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<K, V> node = GetNode(key);
             value = node != null ? node.Value : default;
             return node != null;
@@ -504,10 +482,7 @@ namespace Ryujinx.Common.Collections
 
         public void Add(KeyValuePair<K, V> 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<T>();
 
@@ -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
         /// </summary>
         public void Dispose()
         {
-            if (_disposed)
-            {
-                throw new ObjectDisposedException(GetType().FullName);
-            }
+            ObjectDisposedException.ThrowIf(_disposed, this);
 
             _disposed = true;