checkpoint
This commit is contained in:
52
Alpm/SafeListHandle`1.cs
Normal file
52
Alpm/SafeListHandle`1.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Foodsoft.Alpm
|
||||
{
|
||||
internal sealed class SafeListHandle<TParent> : SafeHandle where TParent: SafeHandle
|
||||
{
|
||||
internal TParent ParentHandle
|
||||
{
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
||||
[PrePrepareMethod]
|
||||
get;
|
||||
} = null!;
|
||||
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
|
||||
[PrePrepareMethod]
|
||||
internal SafeListHandle(IntPtr listPtr, TParent parentHandle)
|
||||
: base(IntPtr.Zero, true)
|
||||
{
|
||||
var success = false;
|
||||
RuntimeHelpers.PrepareConstrainedRegions();
|
||||
try { }
|
||||
finally
|
||||
{
|
||||
parentHandle.DangerousAddRef(ref success);
|
||||
if (success)
|
||||
{
|
||||
ParentHandle = parentHandle;
|
||||
handle = listPtr;
|
||||
}
|
||||
|
||||
}
|
||||
if (!success)
|
||||
throw new ObjectDisposedException(GetType().FullName);
|
||||
}
|
||||
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success), PrePrepareMethod]
|
||||
protected override bool ReleaseHandle()
|
||||
{
|
||||
ParentHandle.DangerousRelease();
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool IsInvalid
|
||||
{
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success), PrePrepareMethod]
|
||||
get => ParentHandle.IsInvalid;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user