From fe37da1b944614edc25521aa41e74c2fc6bb5ec5 Mon Sep 17 00:00:00 2001 From: Haselnussbomber Date: Fri, 24 Oct 2025 02:34:38 +0200 Subject: [PATCH] Fix CA1513: Use ObjectDisposedException.ThrowIf --- Dalamud/Hooking/AsmHook.cs | 5 +---- Dalamud/Hooking/Hook.cs | 5 +---- Dalamud/Interface/ImGuiBackend/Renderers/Dx11Renderer.cs | 6 ++---- .../Internals/FontAtlasFactory.Implementation.cs | 6 ++---- .../Interface/ManagedFontAtlas/Internals/LockedImFont.cs | 3 +-- .../SharedImmediateTextures/SharedImmediateTexture.cs | 4 ++-- Dalamud/Plugin/Internal/Loader/PluginLoader.cs | 3 +-- 7 files changed, 10 insertions(+), 22 deletions(-) diff --git a/Dalamud/Hooking/AsmHook.cs b/Dalamud/Hooking/AsmHook.cs index 09ae336dc..e6c9f61d8 100644 --- a/Dalamud/Hooking/AsmHook.cs +++ b/Dalamud/Hooking/AsmHook.cs @@ -169,9 +169,6 @@ public sealed class AsmHook : IDisposable, IDalamudHook /// private void CheckDisposed() { - if (this.IsDisposed) - { - throw new ObjectDisposedException(message: "Hook is already disposed", null); - } + ObjectDisposedException.ThrowIf(this.IsDisposed, this); } } diff --git a/Dalamud/Hooking/Hook.cs b/Dalamud/Hooking/Hook.cs index faf4658a5..23187ec97 100644 --- a/Dalamud/Hooking/Hook.cs +++ b/Dalamud/Hooking/Hook.cs @@ -242,10 +242,7 @@ public abstract class Hook : IDalamudHook where T : Delegate /// protected void CheckDisposed() { - if (this.IsDisposed) - { - throw new ObjectDisposedException(message: "Hook is already disposed", null); - } + ObjectDisposedException.ThrowIf(this.IsDisposed, this); } private static unsafe IntPtr FromImportHelper32(IntPtr baseAddress, ref PeHeader.IMAGE_IMPORT_DESCRIPTOR desc, ref PeHeader.IMAGE_DATA_DIRECTORY dir, string functionName, uint hintOrOrdinal) diff --git a/Dalamud/Interface/ImGuiBackend/Renderers/Dx11Renderer.cs b/Dalamud/Interface/ImGuiBackend/Renderers/Dx11Renderer.cs index 2eb4e4970..b5a6823d9 100644 --- a/Dalamud/Interface/ImGuiBackend/Renderers/Dx11Renderer.cs +++ b/Dalamud/Interface/ImGuiBackend/Renderers/Dx11Renderer.cs @@ -398,8 +398,7 @@ internal unsafe partial class Dx11Renderer : IImGuiRenderer /// private void CreateFontsTexture() { - if (this.device.IsEmpty()) - throw new ObjectDisposedException(nameof(Dx11Renderer)); + ObjectDisposedException.ThrowIf(this.device.IsEmpty(), this); if (this.fontTextures.Any()) return; @@ -479,8 +478,7 @@ internal unsafe partial class Dx11Renderer : IImGuiRenderer /// private void EnsureDeviceObjects() { - if (this.device.IsEmpty()) - throw new ObjectDisposedException(nameof(Dx11Renderer)); + ObjectDisposedException.ThrowIf(this.device.IsEmpty(), this); var assembly = Assembly.GetExecutingAssembly(); diff --git a/Dalamud/Interface/ManagedFontAtlas/Internals/FontAtlasFactory.Implementation.cs b/Dalamud/Interface/ManagedFontAtlas/Internals/FontAtlasFactory.Implementation.cs index d1fc47447..6e05dea70 100644 --- a/Dalamud/Interface/ManagedFontAtlas/Internals/FontAtlasFactory.Implementation.cs +++ b/Dalamud/Interface/ManagedFontAtlas/Internals/FontAtlasFactory.Implementation.cs @@ -115,16 +115,14 @@ internal sealed partial class FontAtlasFactory public void AddExistingTexture(IDalamudTextureWrap wrap) { - if (this.wraps is null) - throw new ObjectDisposedException(nameof(FontAtlasBuiltData)); + ObjectDisposedException.ThrowIf(this.wraps == null, this); this.wraps.Add(this.Garbage.Add(wrap)); } public int AddNewTexture(IDalamudTextureWrap wrap, bool disposeOnError) { - if (this.wraps is null) - throw new ObjectDisposedException(nameof(FontAtlasBuiltData)); + ObjectDisposedException.ThrowIf(this.wraps == null, this); var handle = wrap.Handle; var index = this.ImTextures.IndexOf(x => x.TexID == handle); diff --git a/Dalamud/Interface/ManagedFontAtlas/Internals/LockedImFont.cs b/Dalamud/Interface/ManagedFontAtlas/Internals/LockedImFont.cs index b7f5ad12b..9eb90fe16 100644 --- a/Dalamud/Interface/ManagedFontAtlas/Internals/LockedImFont.cs +++ b/Dalamud/Interface/ManagedFontAtlas/Internals/LockedImFont.cs @@ -34,8 +34,7 @@ internal class LockedImFont : ILockedImFont /// public ILockedImFont NewRef() { - if (this.owner is null) - throw new ObjectDisposedException(nameof(LockedImFont)); + ObjectDisposedException.ThrowIf(this.owner == null, this); var newRef = new LockedImFont(this.ImFont, this.owner); this.owner.AddRef(); diff --git a/Dalamud/Interface/Textures/Internal/SharedImmediateTextures/SharedImmediateTexture.cs b/Dalamud/Interface/Textures/Internal/SharedImmediateTextures/SharedImmediateTexture.cs index 341cd6062..9264661bd 100644 --- a/Dalamud/Interface/Textures/Internal/SharedImmediateTextures/SharedImmediateTexture.cs +++ b/Dalamud/Interface/Textures/Internal/SharedImmediateTextures/SharedImmediateTexture.cs @@ -476,8 +476,8 @@ internal abstract class SharedImmediateTexture { var ownerCopy = this.owner; var wrapCopy = this.innerWrap; - if (ownerCopy is null || wrapCopy is null) - throw new ObjectDisposedException(nameof(RefCountableWrappingTextureWrap)); + + ObjectDisposedException.ThrowIf(ownerCopy is null || wrapCopy is null, this); ownerCopy.AddRef(); return new RefCountableWrappingTextureWrap(wrapCopy, ownerCopy); diff --git a/Dalamud/Plugin/Internal/Loader/PluginLoader.cs b/Dalamud/Plugin/Internal/Loader/PluginLoader.cs index 54b9cad4b..d8b569356 100644 --- a/Dalamud/Plugin/Internal/Loader/PluginLoader.cs +++ b/Dalamud/Plugin/Internal/Loader/PluginLoader.cs @@ -159,7 +159,6 @@ internal class PluginLoader : IDisposable private void EnsureNotDisposed() { - if (this.disposed) - throw new ObjectDisposedException(nameof(PluginLoader)); + ObjectDisposedException.ThrowIf(this.disposed, this); } }