namespace Brutal.TextureApi { public static partial class ITextureExtensions { /// /// A wrapper class for an ITexture that can be used where IDisposables can; e.g. in /// a using statement. /// When Dispose() is called on an instance of ScopedTexture the ITexture /// is unloaded through the static class. /// public ref struct ScopedTexture : IDisposable { public ScopedTexture(ITexture texture) { Texture = texture; } public ITexture? Texture { get; private set; } public void Dispose() { if (Texture is null) return; TextureLoader.Unload(Texture); Texture = null; } } /// /// Wraps an ITexture in an IDisposable /// /// The ITexture to wrap /// The ScopedTexture wrapper public static ScopedTexture Using(this ITexture texture) { return new ScopedTexture(texture); } } }