InvokeMethod() static private method

static private InvokeMethod ( object target, HelpOptionAttribute>.Pair pair, string &text ) : void
target object
pair HelpOptionAttribute>.Pair
text string
return void
Esempio n. 1
0
        /// <summary>
        /// Parses a <see cref="System.String"/> array of command line arguments, setting values in <paramref name="options"/>
        /// parameter instance's public fields decorated with appropriate attributes.
        /// This overload allows you to specify a <see cref="System.IO.TextWriter"/> derived instance for write text messages.
        /// </summary>
        /// <param name="args">A <see cref="System.String"/> array of command line arguments.</param>
        /// <param name="options">An object's instance used to receive values.
        /// Parsing rules are defined using <see cref="CommandLine.BaseOptionAttribute"/> derived types.</param>
        /// <param name="helpWriter">Any instance derived from <see cref="System.IO.TextWriter"/>,
        /// usually <see cref="System.Console.Error"/>. Setting this argument to null, will disable help screen.</param>
        /// <returns>True if parsing process succeed.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown if <paramref name="args"/> is null.</exception>
        /// <exception cref="System.ArgumentNullException">Thrown if <paramref name="options"/> is null.</exception>
        public virtual bool ParseArguments(string[] args, object options, TextWriter helpWriter)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            var pair = ReflectionUtil.RetrieveMethod <HelpOptionAttribute>(options);

            if (pair != null && helpWriter != null)
            {
                if (ParseHelp(args, pair.Right) || !DoParseArguments(args, options))
                {
                    string helpText;
                    HelpOptionAttribute.InvokeMethod(options, pair, out helpText);
                    helpWriter.Write(helpText);
                    return(false);
                }
                return(true);
            }

            return(DoParseArguments(args, options));
        }
Esempio n. 2
0
        private bool DoParseArguments(string[] args, object options)
        {
            var pair       = ReflectionHelper.RetrieveMethod <HelpOptionAttribute>(options);
            var helpWriter = _settings.HelpWriter;

            if (pair != null && helpWriter != null)
            {
                // If help can be handled is displayed if is requested or if parsing fails
                if (ParseHelp(args, pair.Right) || !DoParseArgumentsCore(args, options))
                {
                    string helpText;
                    HelpOptionAttribute.InvokeMethod(options, pair, out helpText);
                    helpWriter.Write(helpText);
                    return(false);
                }

                return(true);
            }

            return(DoParseArgumentsCore(args, options));
        }
        /// <summary>
        /// Parses a <see cref="System.String"/> array of command line arguments,
        /// setting values read in <paramref name="options"/> parameter instance.
        /// This overloads allows you to specify a <see cref="System.IO.TextWriter"/>
        /// derived instance for write text messages.
        /// </summary>
        /// <param name="args">A <see cref="System.String"/> array of command line arguments.</param>
        /// <param name="options">An instance to receive values.
        /// Parsing rules are defined using <see cref="CommandLine.BaseOptionAttribute"/> derived types.</param>
        /// <param name="helpWriter">Any instance derived from <see cref="System.IO.TextWriter"/>,
        /// usually <see cref="System.Console.Out"/>.</param>
        /// <returns>True if parsing process succeed.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown if <paramref name="args"/> is null.</exception>
        /// <exception cref="System.ArgumentNullException">Thrown if <paramref name="options"/> is null.</exception>
        /// <exception cref="System.ArgumentNullException">Thrown if <paramref name="helpWriter"/> is null.</exception>
        public static bool ParseArguments(string[] args, object options, TextWriter helpWriter)
        {
            Validator.CheckIsNull(args, "args");
            Validator.CheckIsNull(options, "options");
            Validator.CheckIsNull(helpWriter, "helpWriter");

            Pair <MethodInfo, HelpOptionAttribute> pair =
                ReflectionUtil.RetrieveMethod <HelpOptionAttribute>(options);

            if (pair == null)
            {
                throw new InvalidOperationException();
            }
            if (ParseHelp(args, pair.Right) || !ParseArgumentList(args, options))
            {
                string helpText;
                HelpOptionAttribute.InvokeMethod(options, pair, out helpText);
                helpWriter.Write(helpText);
                return(false);
            }
            return(true);
        }