32 lines
No EOL
692 B
C#
32 lines
No EOL
692 B
C#
using System;
|
|
|
|
namespace JD.Core
|
|
{
|
|
/// <summary>
|
|
/// Helper to manipulate disposable objects.
|
|
/// </summary>
|
|
public static class Disposable
|
|
{
|
|
public static IDisposable FromAction(Action action)
|
|
{
|
|
return new DisposableHelper(action);
|
|
}
|
|
|
|
private class DisposableHelper : IDisposable
|
|
{
|
|
private Action _action;
|
|
|
|
public DisposableHelper(Action action)
|
|
{
|
|
_action = action;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
var action = _action;
|
|
_action = null;
|
|
action?.Invoke();
|
|
}
|
|
}
|
|
}
|
|
} |