// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Threading.Tasks; namespace Microsoft.AspNetCore.Blazor.Components { /// /// A bound event handler delegate. /// public struct EventHandlerInvoker { private readonly MulticastDelegate _delegate; /// /// Creates the new . /// /// The delegate to bind. public EventHandlerInvoker(MulticastDelegate @delegate) { _delegate = @delegate; } /// /// Invokes the delegate associated with this binding. /// /// The . /// public Task Invoke(UIEventArgs e) { switch (_delegate) { case Action action: action.Invoke(); return Task.CompletedTask; case Action actionEventArgs: actionEventArgs.Invoke(e); return Task.CompletedTask; case Func func: return func.Invoke(); case Func funcEventArgs: return funcEventArgs.Invoke(e); case MulticastDelegate @delegate: return @delegate.DynamicInvoke(e) as Task ?? Task.CompletedTask; case null: return Task.CompletedTask; } } } }