DisposeHelper
using System;
using System.Runtime.CompilerServices;
namespace NUnit.Framework.Internal
{
internal static class DisposeHelper
{
[System.Runtime.CompilerServices.NullableContext(1)]
public static bool IsDisposable(Type type)
{
if (typeof(IDisposable).IsAssignableFrom(type))
return true;
return typeof(IAsyncDisposable).IsAssignableFrom(type);
}
[System.Runtime.CompilerServices.NullableContext(2)]
public static void EnsureDisposed(object value)
{
if (value != null) {
IAsyncDisposable asyncDisposable = value as IAsyncDisposable;
if (asyncDisposable != null)
AsyncToSyncAdapter.Await(() => asyncDisposable.DisposeAsync());
else
(value as IDisposable)?.Dispose();
}
}
}
}