You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.4 KiB
58 lines
1.4 KiB
5 years ago
|
// Needed for NET40
|
||
|
#if !NET_4_6
|
||
|
using System;
|
||
|
|
||
|
using LinqInternal.Core;
|
||
|
|
||
|
namespace LinqInternal.Threading
|
||
|
{
|
||
|
[System.Diagnostics.DebuggerNonUserCode]
|
||
|
public sealed partial class Disposable
|
||
|
{
|
||
|
private Action _release;
|
||
|
|
||
|
private Disposable(Action release)
|
||
|
{
|
||
|
if (release == null)
|
||
|
{
|
||
|
throw new ArgumentNullException("release");
|
||
|
}
|
||
|
_release = release;
|
||
|
}
|
||
|
|
||
|
public static Disposable Create()
|
||
|
{
|
||
|
return new Disposable(ActionHelper.GetNoopAction());
|
||
|
}
|
||
|
|
||
|
public static Disposable Create(Action release)
|
||
|
{
|
||
|
return new Disposable(release);
|
||
|
}
|
||
|
|
||
|
public bool Dispose(Func<bool> condition)
|
||
|
{
|
||
|
if (condition == null)
|
||
|
{
|
||
|
throw new ArgumentNullException("condition");
|
||
|
}
|
||
|
return DisposedConditional
|
||
|
(
|
||
|
FuncHelper.GetFallacyFunc(),
|
||
|
() =>
|
||
|
{
|
||
|
if (condition.Invoke())
|
||
|
{
|
||
|
Dispose();
|
||
|
return true;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
#endif
|