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

MethodInfoExtensions

static class MethodInfoExtensions
using System; using System.Reflection; using System.Runtime.CompilerServices; namespace NUnit.Framework.Internal.Extensions { [System.Runtime.CompilerServices.NullableContext(2)] [System.Runtime.CompilerServices.Nullable(0)] internal static class MethodInfoExtensions { public static TReturn InvokeMaybeAwait<TReturn>([System.Runtime.CompilerServices.Nullable(1)] this MethodInfo m) { return m.InvokeMaybeAwait<TReturn>(null); } public static TReturn InvokeMaybeAwait<TReturn>([System.Runtime.CompilerServices.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); } [System.Runtime.CompilerServices.NullableContext(1)] public static T CreateDelegate<[System.Runtime.CompilerServices.Nullable(0)] T>(this MethodInfo m, object target) where T : Delegate { return (T)m.CreateDelegate(typeof(T), target); } } }