46 lines
1.2 KiB
C#
46 lines
1.2 KiB
C#
using System;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Runtime.ConstrainedExecution;
|
|
|
|
namespace Foodsoft.Alpm
|
|
{
|
|
internal struct ListRef : CriticalFinalIDisposable
|
|
{
|
|
public SafeAlpmHandle SafeAlpmHandle
|
|
{
|
|
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
|
[PrePrepareMethod]
|
|
get;
|
|
}
|
|
|
|
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail), PrePrepareMethod]
|
|
public ListRef(SafeAlpmHandle handle)
|
|
{
|
|
SafeAlpmHandle = null!;
|
|
RuntimeHelpers.PrepareConstrainedRegions();
|
|
try { }
|
|
finally
|
|
{
|
|
SafeAlpmHandle = handle;
|
|
var success = false;
|
|
handle.DangerousAddRef(ref success);
|
|
if (success)
|
|
SafeAlpmHandle = handle;
|
|
else
|
|
{
|
|
SafeAlpmHandle = null!;
|
|
throw new ObjectDisposedException(GetType().FullName);
|
|
}
|
|
}
|
|
}
|
|
|
|
~ListRef()
|
|
{
|
|
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
}
|
|
}
|
|
} |