MethodInfoExtensions
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);
}
}
}