using System;
using System.ComponentModel;
using System.Runtime.InteropServices;

namespace Decal.Adapter;

public class GenericDisposableWrapper<T> : DisposableByRefObject where T : class
{
	private T myObj;

	[CLSCompliant(false)]
	[EditorBrowsable(EditorBrowsableState.Never)]
	public T Underlying => myObj;

	[CLSCompliant(false)]
	protected T Wrapped => myObj;

	internal GenericDisposableWrapper(T obj)
	{
		myObj = obj;
	}

	protected override void Dispose(bool userCalled)
	{
		EnforceDisposedOnce();
		base.Dispose(userCalled);
		if (myObj != null)
		{
			Marshal.ReleaseComObject(myObj);
		}
	}
}
