using System.Reflection; using System.Runtime.CompilerServices; namespace TIAMWebApp.Server.Services; public static class ExtensionMethods { public static object? InvokeMethod(this MethodInfo methodInfo, object obj, params object[]? parameters) { if (methodInfo.GetCustomAttribute(typeof(AsyncStateMachineAttribute)) is AsyncStateMachineAttribute isAsyncTask) { dynamic awaitable = methodInfo.Invoke(obj, parameters)!; return awaitable.GetAwaiter().GetResult(); } return methodInfo.Invoke(obj, parameters); } }