<PackageReference Include="NUnit" Version="4.3.1" />

DisposeHelper

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