Files
DotNetAlpm/Alpm/SafeAlpmHandle.cs
2020-04-30 20:42:46 -04:00

25 lines
688 B
C#

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;
}
}
}