On
Enables the Dispose syntax.
using System;
using System.Runtime.CompilerServices;
using System.Threading;
namespace NUnit.Framework.Internal
{
internal static class On
{
private sealed class DisposableAction : IDisposable
{
[System.Runtime.CompilerServices.Nullable(2)]
private Action _action;
[System.Runtime.CompilerServices.NullableContext(1)]
public DisposableAction(Action action)
{
_action = action;
}
public void Dispose()
{
Interlocked.Exchange(ref _action, null)?.Invoke();
}
}
[System.Runtime.CompilerServices.NullableContext(1)]
public static IDisposable Dispose(Action action)
{
if (action == null)
throw new ArgumentNullException("action");
return new DisposableAction(action);
}
}
}