示例#1
0
        /// <summary>
        /// Activate this switch when found
        /// </summary>
        /// <param name="arguments">Arguments from the command line.</param>
        public override bool TryActivate(Queue <string> arguments)
        {
            if (arguments == null)
            {
                throw new ArgumentNullException(nameof(arguments));
            }

            if (arguments.Count == 0)
            {
                return(false);
            }

            var arg = arguments.Peek();

            if (ShortName.Equals(arg, StringComparison.CurrentCultureIgnoreCase) ||
                AlternateShortName.Equals(arg, StringComparison.CurrentCultureIgnoreCase) ||
                LongName.Equals(arg, StringComparison.CurrentCultureIgnoreCase))
            {
                arguments.Dequeue();
                _method.Invoke(_instance, null);
                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Activate this parameter when found
        /// </summary>
        /// <param name="arguments">Arguments to process.</param>
        public override bool TryActivate(Queue <string> arguments)
        {
            if (arguments == null)
            {
                throw new ArgumentNullException(nameof(arguments));
            }

            if (arguments.Count == 0)
            {
                return(false);
            }

            var arg = arguments.Peek();

            if (arg.StartsWith(ShortName + ":", StringComparison.CurrentCultureIgnoreCase) ||
                arg.StartsWith(AlternateShortName + ":", StringComparison.CurrentCultureIgnoreCase) ||
                arg.StartsWith(LongName + ":", StringComparison.CurrentCultureIgnoreCase))
            {
                arguments.Dequeue();
                var value = arg.After(":").As <V>();
                _values.Add(value);
                return(true);
            }

            if (ShortName.Equals(arg, StringComparison.CurrentCultureIgnoreCase) ||
                AlternateShortName.Equals(arg, StringComparison.CurrentCultureIgnoreCase) ||
                LongName.Equals(arg, StringComparison.CurrentCultureIgnoreCase))
            {
                arguments.Dequeue();

                if (arguments.Count < 1)
                {
                    _valueMissing = true;
                    return(true);
                }

                var value = arguments.Dequeue().As <V>();
                _values.Add(value);
                return(true);
            }

            return(false);
        }