Fix CA1513: Use ObjectDisposedException.ThrowIf

This commit is contained in:
Haselnussbomber 2025-10-24 02:34:38 +02:00
parent 6bdc785273
commit fe37da1b94
No known key found for this signature in database
GPG key ID: BB905BB49E7295D1
7 changed files with 10 additions and 22 deletions

View file

@ -169,9 +169,6 @@ public sealed class AsmHook : IDisposable, IDalamudHook
/// </summary> /// </summary>
private void CheckDisposed() private void CheckDisposed()
{ {
if (this.IsDisposed) ObjectDisposedException.ThrowIf(this.IsDisposed, this);
{
throw new ObjectDisposedException(message: "Hook is already disposed", null);
}
} }
} }

View file

@ -242,10 +242,7 @@ public abstract class Hook<T> : IDalamudHook where T : Delegate
/// </summary> /// </summary>
protected void CheckDisposed() protected void CheckDisposed()
{ {
if (this.IsDisposed) ObjectDisposedException.ThrowIf(this.IsDisposed, this);
{
throw new ObjectDisposedException(message: "Hook is already disposed", null);
}
} }
private static unsafe IntPtr FromImportHelper32(IntPtr baseAddress, ref PeHeader.IMAGE_IMPORT_DESCRIPTOR desc, ref PeHeader.IMAGE_DATA_DIRECTORY dir, string functionName, uint hintOrOrdinal) private static unsafe IntPtr FromImportHelper32(IntPtr baseAddress, ref PeHeader.IMAGE_IMPORT_DESCRIPTOR desc, ref PeHeader.IMAGE_DATA_DIRECTORY dir, string functionName, uint hintOrOrdinal)

View file

@ -398,8 +398,7 @@ internal unsafe partial class Dx11Renderer : IImGuiRenderer
/// </summary> /// </summary>
private void CreateFontsTexture() private void CreateFontsTexture()
{ {
if (this.device.IsEmpty()) ObjectDisposedException.ThrowIf(this.device.IsEmpty(), this);
throw new ObjectDisposedException(nameof(Dx11Renderer));
if (this.fontTextures.Any()) if (this.fontTextures.Any())
return; return;
@ -479,8 +478,7 @@ internal unsafe partial class Dx11Renderer : IImGuiRenderer
/// </summary> /// </summary>
private void EnsureDeviceObjects() private void EnsureDeviceObjects()
{ {
if (this.device.IsEmpty()) ObjectDisposedException.ThrowIf(this.device.IsEmpty(), this);
throw new ObjectDisposedException(nameof(Dx11Renderer));
var assembly = Assembly.GetExecutingAssembly(); var assembly = Assembly.GetExecutingAssembly();

View file

@ -115,16 +115,14 @@ internal sealed partial class FontAtlasFactory
public void AddExistingTexture(IDalamudTextureWrap wrap) public void AddExistingTexture(IDalamudTextureWrap wrap)
{ {
if (this.wraps is null) ObjectDisposedException.ThrowIf(this.wraps == null, this);
throw new ObjectDisposedException(nameof(FontAtlasBuiltData));
this.wraps.Add(this.Garbage.Add(wrap)); this.wraps.Add(this.Garbage.Add(wrap));
} }
public int AddNewTexture(IDalamudTextureWrap wrap, bool disposeOnError) public int AddNewTexture(IDalamudTextureWrap wrap, bool disposeOnError)
{ {
if (this.wraps is null) ObjectDisposedException.ThrowIf(this.wraps == null, this);
throw new ObjectDisposedException(nameof(FontAtlasBuiltData));
var handle = wrap.Handle; var handle = wrap.Handle;
var index = this.ImTextures.IndexOf(x => x.TexID == handle); var index = this.ImTextures.IndexOf(x => x.TexID == handle);

View file

@ -34,8 +34,7 @@ internal class LockedImFont : ILockedImFont
/// <inheritdoc/> /// <inheritdoc/>
public ILockedImFont NewRef() public ILockedImFont NewRef()
{ {
if (this.owner is null) ObjectDisposedException.ThrowIf(this.owner == null, this);
throw new ObjectDisposedException(nameof(LockedImFont));
var newRef = new LockedImFont(this.ImFont, this.owner); var newRef = new LockedImFont(this.ImFont, this.owner);
this.owner.AddRef(); this.owner.AddRef();

View file

@ -476,8 +476,8 @@ internal abstract class SharedImmediateTexture
{ {
var ownerCopy = this.owner; var ownerCopy = this.owner;
var wrapCopy = this.innerWrap; 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(); ownerCopy.AddRef();
return new RefCountableWrappingTextureWrap(wrapCopy, ownerCopy); return new RefCountableWrappingTextureWrap(wrapCopy, ownerCopy);

View file

@ -159,7 +159,6 @@ internal class PluginLoader : IDisposable
private void EnsureNotDisposed() private void EnsureNotDisposed()
{ {
if (this.disposed) ObjectDisposedException.ThrowIf(this.disposed, this);
throw new ObjectDisposedException(nameof(PluginLoader));
} }
} }