public async Task InvokeAsync([NotNull] ViewComponentContext context) { IViewComponentResult result; var asyncMethod = ViewComponentMethodSelector.FindAsyncMethod(_componentType, _args); if (asyncMethod == null) { // We support falling back to synchronous if there is no InvokeAsync method, in this case we'll still // execute the IViewResult asynchronously. var syncMethod = ViewComponentMethodSelector.FindSyncMethod(_componentType, _args); if (syncMethod == null) { throw new InvalidOperationException( Resources.FormatViewComponent_CannotFindMethod_WithFallback( ViewComponentMethodSelector.SyncMethodName, ViewComponentMethodSelector.AsyncMethodName)); } else { result = InvokeSyncCore(syncMethod, context.ViewContext); } } else { result = await InvokeAsyncCore(asyncMethod, context.ViewContext); } await result.ExecuteAsync(context); }
public void Invoke([NotNull] ViewComponentContext context) { var method = ViewComponentMethodSelector.FindSyncMethod(_componentType, _args); if (method == null) { throw new InvalidOperationException( Resources.FormatViewComponent_CannotFindMethod(ViewComponentMethodSelector.SyncMethodName)); } var result = InvokeSyncCore(method, context.ViewContext); result.Execute(context); }