Example #1
0
        /// <summary>
        /// Try to parse arguments into <typeparamref name="T1"/>
        /// and get the respective <see cref="ArgsParseResult{T}"/>.
        /// This is a type-safe wrapper around <see cref="ArgsParser.ParseRaw"/>.
        /// </summary>
        /// <param name="argsParser">args parser used for parsing</param>
        /// <param name="args">List of string arguments to parse from.</param>
        /// <typeparam name="T1">Type to attempt to create an instance of.</typeparam>
        /// <returns>The respective parse result,
        /// containing an instance of <c>T1</c> on success.</returns>
        public static async Task <ArgsParseResult <T1> > TryParse <T1>(
            this ArgsParser argsParser, IImmutableList <string> args)
        {
            IEnumerable <Type> types = new[] { typeof(T1) };
            ArgsParseResult <List <object> > parseResult = await argsParser.ParseRaw(args, types, errorOnRemainingArgs : true);

            if (parseResult.SuccessResult == null)
            {
                return(ArgsParseResult <T1> .Failure(parseResult.Failures));
            }
            Success <List <object> > success = parseResult.SuccessResult.Value;

            return(ArgsParseResult <T1> .Success(parseResult.Failures,
                                                 (T1)success.Result[0],
                                                 success.RemainingArgs));
        }
Example #2
0
     this ArgsParser argsParser, IImmutableList <string> args)
 {