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

MethodInfoExtensions

static class MethodInfoExtensions
using System.Reflection; using System.Runtime.CompilerServices; namespace NUnit.Framework.Internal.Extensions { [NullableContext(2)] [Nullable(0)] internal static class MethodInfoExtensions { public static TReturn InvokeMaybeAwait<TReturn>([Nullable(1)] this MethodInfo m) { return m.InvokeMaybeAwait<TReturn>(null); } public static TReturn InvokeMaybeAwait<TReturn>([Nullable(1)] this MethodInfo m, object[] methodArgs) { if (AsyncToSyncAdapter.IsAsyncOperation(m)) return (TReturn)AsyncToSyncAdapter.Await(null, () => m.Invoke(null, methodArgs)); return (TReturn)m.Invoke(null, methodArgs); } } }