/// <summary>
        /// Adds a <see cref="Switch"/> to the <see cref="OptionSet"/>.
        /// </summary>
        /// <param name="options"></param>
        /// <param name="prototype"></param>
        /// <param name="callback"></param>
        /// <param name="description"></param>
        /// <returns>The <see cref="Switch"/> associated with the <paramref name="options"/>.</returns>
        public static Switch AddSwitch(this OptionSet options, string prototype
                                       , OptionCallback callback, string description = null)
        {
            /* Switch and not a flag. Switch implies on or off, enabled or disabled,
             * whereas flag implies combinations, masking. */
            var result = new Switch();

            options.Add(prototype, description, () =>
            {
                result.Enabled = true;
                callback?.Invoke();
            });

            // Return the near-future Switch instance.
            return(result);
        }
        /// <summary>
        /// Accumulates <typeparamref name="T"/> into a strongly-typed
        /// <see cref="VariableMatrix{T}"/>.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="options"></param>
        /// <param name="prototype"></param>
        /// <param name="callback"></param>
        /// <param name="description"></param>
        /// <returns>The <see cref="VariableMatrix{T}"/> associated with the
        /// <paramref name="options"/>.</returns>
        public static VariableMatrix <T> AddVariableMatrix <T>(this OptionSet options, string prototype, OptionCallback <string, T> callback, string description = null)
        {
            var result = new VariableMatrix <T>(prototype);

            options.Add <string, T>(prototype, description, (k, x) =>
            {
                if (IsNullOrEmpty(k))
                {
                    throw new OptionException("Name not specified", prototype, null);
                }

                result.InternalMatrix.Add(k, x);
                callback?.Invoke(k, x);
            });

            // Return with the near-future Variable instance.
            return(result);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Adds the <see cref="Option"/> corresponding with the arguments
 /// to the end of the Collection.
 /// </summary>
 /// <param name="prototype"></param>
 /// <param name="description"></param>
 /// <param name="callback"></param>
 /// <returns></returns>
 public OptionSet Add(string prototype, string description, OptionCallback callback)
 => Add(callback
        // ReSharper disable once ConvertClosureToMethodGroup
        , () => new SimpleActionOption(prototype, description, () => callback.Invoke())
        );
Exemplo n.º 4
0
 /// <summary>
 /// Adds the <see cref="KeyValueActionOption{TKey,TValue}"/> corresponding with the
 /// arguments to the end of the Collection.
 /// </summary>
 /// <param name="prototype"></param>
 /// <param name="description"></param>
 /// <param name="callback"></param>
 /// <returns></returns>
 public OptionSet Add <TKey, TValue>(string prototype, string description, OptionCallback <TKey, TValue> callback)
 => Add(callback
        // ReSharper disable once ConvertClosureToMethodGroup
        , () => new KeyValueActionOption <TKey, TValue>(prototype, description, (k, v) => callback.Invoke(k, v))
        );
Exemplo n.º 5
0
 public void RaiseOptionChanged()
 {
     OptionCallback.Invoke(this);
 }