public static MethodInfo FindSyncMethod(WidgetContext context, TypeInfo widgetType)
{
string httpMethod = ResolveHttpMethod(context);
string state = string.Empty; // Resolve a widget state?
MethodInfo method = null;
for (int i = 0; i < SyncMethodNames.Length; i++)
{
string name = string.Format(SyncMethodNames[i], state, httpMethod);
method = GetMethod(name, widgetType);
if (method != null)
{
break;
}
}
if (method == null)
{
return null;
}
if (method.ReturnType == typeof(void))
{
throw new InvalidOperationException($"Sync method '{method.Name}' should return a value.");
}
if (method.ReturnType.IsAssignableFrom(typeof(Task)))
{
throw new InvalidOperationException($"Sync method '{method.Name}' cannot return a task.");
}
return method;
}