private class DisposableAction : IDisposable { private readonly Action action; public DisposableAction(Action action) { this.action = action ?? throw new ArgumentNullException(nameof(action)); } public void Dispose() { action(); } }
351700cookie-checkC# Action on dispose