using System; using System.Runtime.CompilerServices; using System.Runtime.ConstrainedExecution; using System.Runtime.InteropServices; namespace Foodsoft.Alpm { internal class SafeFilePackageHandle : SafePackageHandle { internal SafeAlpmHandle SafeAlpmHandle { get; } = null!; [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] [PrePrepareMethod] internal SafeFilePackageHandle(IntPtr ptr, SafeAlpmHandle parentHandle) { var success = false; RuntimeHelpers.PrepareConstrainedRegions(); try { } finally { parentHandle.DangerousAddRef(ref success); if (success) { SafeAlpmHandle = parentHandle; handle = ptr; } } if (!success) throw new ObjectDisposedException(GetType().FullName); } protected override bool ReleaseHandle() { SafeAlpmHandle.DangerousRelease(); return true; } } }