/// <summary> /// Initializes a new instance of <see cref="UIActionBinding"/>. /// </summary> /// <param name="binding"> /// A set of default suggested interfaces for a <see cref="UIAction"/>. /// </param> /// <param name="handler"> /// The handler function used to invoke the <see cref="UIAction"/> and determine its <see cref="UIActionState"/>. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="binding"/> and/or <paramref name="handler"/> are null. /// </exception> public UIActionBinding(DefaultUIActionBinding binding, UIActionHandlerFunc handler) { if (binding == null) { throw new ArgumentNullException(nameof(binding)); } Action = binding.Action; Interfaces = binding.DefaultInterfaces; Handler = handler ?? throw new ArgumentNullException(nameof(handler)); }
/// <summary> /// Binds a handler function for a <see cref="UIAction"/> to a <see cref="IUIActionHandlerProvider"/>, /// and specifies how this <see cref="UIAction"/> is exposed to the user interface. /// </summary> /// <typeparam name="T"> /// The type of <paramref name="provider"/>. /// </typeparam> /// <param name="provider"> /// The <see cref="Control"/> which allows binding of actions by implementing the <see cref="IUIActionHandlerProvider"/> interface. /// </param> /// <param name="action"> /// The <see cref="UIAction"/> to bind. /// </param> /// <param name="interfaces"> /// The <see cref="IUIActionInterface"/> set which defines how the action is exposed to the user interface. /// </param> /// <param name="handler"> /// The handler function used to perform the <see cref="UIAction"/> and determine its <see cref="UIActionState"/>. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="action"/> and/or <paramref name="interfaces"/> and/or <paramref name="handler"/> are null. /// </exception> public static void BindAction <T>(this T provider, UIAction action, ImplementationSet <IUIActionInterface> interfaces, UIActionHandlerFunc handler) where T : Control, IUIActionHandlerProvider => BindAction(provider, new UIActionBinding(action, interfaces, handler));
/// <summary> /// Binds a handler function for a <see cref="UIAction"/> to a <see cref="IUIActionHandlerProvider"/>, /// and specifies how this <see cref="UIAction"/> is exposed to the user interface. /// </summary> /// <typeparam name="T"> /// The type of <paramref name="provider"/>. /// </typeparam> /// <param name="provider"> /// The <see cref="Control"/> which allows binding of actions by implementing the <see cref="IUIActionHandlerProvider"/> interface. /// </param> /// <param name="binding"> /// Contains the <see cref="UIAction"/> with its suggested default <see cref="IUIActionInterface"/> set. /// </param> /// <param name="handler"> /// The handler function used to perform the <see cref="UIAction"/> and determine its <see cref="UIActionState"/>. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="binding"/> and/or <paramref name="handler"/> are null. /// </exception> public static void BindAction <T>(this T provider, DefaultUIActionBinding binding, UIActionHandlerFunc handler) where T : Control, IUIActionHandlerProvider => BindAction(provider, new UIActionBinding(binding, handler));
/// <summary> /// Initializes a new instance of <see cref="UIActionBinding"/>. /// </summary> /// <param name="action"> /// The <see cref="UIAction"/> to bind to a <see cref="UIActionHandler"/>. /// </param> /// <param name="interfaces"> /// The <see cref="IUIActionInterface"/> set which defines how the action is exposed to the user interface. /// </param> /// <param name="handler"> /// The handler function used to invoke the <see cref="UIAction"/> and determine its <see cref="UIActionState"/>. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="action"/> and/or <paramref name="interfaces"/> and/or <paramref name="handler"/> are null. /// </exception> public UIActionBinding(UIAction action, ImplementationSet <IUIActionInterface> interfaces, UIActionHandlerFunc handler) { Action = action ?? throw new ArgumentNullException(nameof(action)); Interfaces = interfaces ?? throw new ArgumentNullException(nameof(interfaces)); Handler = handler ?? throw new ArgumentNullException(nameof(handler)); }