public static MethodInfo FindAsyncMethod(WidgetContext context, TypeInfo widgetType)
{
string httpMethod = ResolveHttpMethod(context);
string state = string.Empty; // Resolve a widget state?
MethodInfo method = null;
for (int i = 0; i < AsyncMethodNames.Length; i++)
{
string name = string.Format(AsyncMethodNames[i], state, httpMethod);
method = GetMethod(name, widgetType);
if (method != null)
{
break;
}
}
if (method == null)
{
return null;
}
if (!method.ReturnType.GetTypeInfo().IsGenericType
|| method.ReturnType.GetGenericTypeDefinition() != typeof(Task<>))
{
throw new InvalidOperationException($"Async method '{method.Name}' must return a task.");
}
return method;
}