using System; using System.Runtime.ConstrainedExecution; using System.Runtime.InteropServices; namespace Foodsoft.Alpm { internal sealed class SafeAlpmHandle : SafeHandle { private SafeAlpmHandle() : base(IntPtr.Zero, true) { } public override bool IsInvalid { [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] [PrePrepareMethod] get => handle == IntPtr.Zero; } [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] [PrePrepareMethod] protected override bool ReleaseHandle() { return alpm.alpm_release(handle) == 0; } } }