mirror of
https://github.com/Maassoft/ColorControl.git
synced 2026-10-21 16:12:18 -05:00
47 lines
1021 B
C#
47 lines
1021 B
C#
using System;
|
|
|
|
namespace LittleCms
|
|
{
|
|
public abstract class CmsObject
|
|
{
|
|
private IntPtr handle;
|
|
private bool isOwner;
|
|
|
|
public IntPtr Handle => handle;
|
|
public bool IsOwner => isOwner;
|
|
|
|
public abstract CmsContext Context { get; }
|
|
|
|
|
|
protected CmsObject() { }
|
|
|
|
protected CmsObject(IntPtr handle, bool moveOwnership)
|
|
{
|
|
AttachObject(handle, isOwner);
|
|
}
|
|
|
|
|
|
protected void AttachObject(IntPtr handle, bool moveOwnership)
|
|
{
|
|
if (handle != IntPtr.Zero && isOwner)
|
|
{
|
|
FreeObject();
|
|
}
|
|
if (handle == IntPtr.Zero)
|
|
{
|
|
throw new NullReferenceException();
|
|
}
|
|
this.handle = handle;
|
|
this.isOwner = moveOwnership;
|
|
}
|
|
|
|
~CmsObject() {
|
|
if (handle != IntPtr.Zero && isOwner) {
|
|
FreeObject();
|
|
}
|
|
}
|
|
|
|
protected abstract void FreeObject();
|
|
}
|
|
}
|