ContextUtils
using System;
using System.Runtime.CompilerServices;
using System.Threading;
namespace NUnit.Framework.Internal
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
internal static class ContextUtils
{
public static void DoIsolated(Action action)
{
DoIsolated(delegate {
action();
}, null);
}
public static T DoIsolated<[System.Runtime.CompilerServices.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, [System.Runtime.CompilerServices.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();
}
}
}
}