---
source: boltffi_bindgen/src/render/csharp/templates.rs
expression: template.render().unwrap()
---
// <auto-generated>
// This file was generated by BoltFFI. Do not edit.
// </auto-generated>
#nullable enable

using System;
using System.Threading;

namespace Demo
{
    public sealed class Inventory : IDisposable
    {
        private IntPtr _handle;

        internal Inventory(IntPtr handle)
        {
            _handle = handle;
        }

        public Inventory()
            : this(InventoryNewHandle()) { }

        private static IntPtr InventoryNewHandle()
        {
            return NativeMethods.InventoryNew();
        }

        public static Inventory WithCapacity(uint capacity)
        {
            return new Inventory(NativeMethods.InventoryWithCapacity(capacity));
        }

        internal IntPtr RawHandle => _handle;

        private void ThrowIfDisposed()
        {
            if (_handle == IntPtr.Zero) throw new ObjectDisposedException(nameof(Inventory));
        }

        public void Dispose()
        {
            IntPtr handle = Interlocked.Exchange(ref _handle, IntPtr.Zero);
            if (handle == IntPtr.Zero) return;
            NativeMethods.InventoryFree(handle);
            GC.SuppressFinalize(this);
        }

        ~Inventory()
        {
            Dispose();
        }
    }
}
