Antaris.AspNetCore.Mvc.Widgets.Internal.WidgetMethodSelector.FindSyncMethod C# (CSharp) Method

FindSyncMethod() public static method

Finds a synchronous method to execute.
public static FindSyncMethod ( WidgetContext context, TypeInfo widgetType ) : MethodInfo
context Antaris.AspNetCore.Mvc.Widgets.Infrastructure.WidgetContext The widget context.
widgetType System.Reflection.TypeInfo The widget type.
return System.Reflection.MethodInfo
        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;
        }