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

ContextUtils

static class ContextUtils
using System; using System.Runtime.CompilerServices; using System.Threading; namespace NUnit.Framework.Internal { [NullableContext(1)] [Nullable(0)] internal static class ContextUtils { public static void DoIsolated(Action action) { DoIsolated(delegate { action(); }, null); } public static T DoIsolated<[Nullable(2)] T>(Func<T> func) { T returnValue = (T)default(T); DoIsolated(delegate { returnValue = (T)func(); }, null); return (T)returnValue; } public static void DoIsolated(ContextCallback callback, [Nullable(2)] object state) { SandboxedThreadState sandboxedThreadState = SandboxedThreadState.Capture(); try { ExecutionContext executionContext = ExecutionContext.Capture(); if (executionContext == null) throw new InvalidOperationException("Execution context flow must not be suppressed."); ExecutionContext executionContext2 = executionContext; using (executionContext2) ExecutionContext.Run(executionContext2, callback, state); } finally { sandboxedThreadState.Restore(); } } } }