Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ArgumentResult"/> class.
        /// </summary>
        /// <param name="argument">The argument.</param>
        /// <param name="values">The values. Can be <see langword="null"/>.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="argument"/> is <see langword="null"/>.
        /// </exception>
        protected ArgumentResult(Argument argument, IEnumerable values)
        {
            if (argument == null)
                throw new ArgumentNullException(nameof(argument));

            Argument = argument;
            Values = values ?? Array.Empty<object>();
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ArgumentResult"/> class.
        /// </summary>
        /// <param name="argument">The argument.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="argument"/> is <see langword="null"/>.
        /// </exception>
        public ArgumentResult(Argument argument)
        {
            if (argument == null)
                throw new ArgumentNullException(nameof(argument));

            Argument = argument;
            Values = Array.Empty<object>();
        }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DuplicateArgumentException"/> class.
 /// </summary>
 /// <param name="argument">The missing argument.</param>
 /// <param name="message">The message.</param>
 /// <param name="innerException">The inner exception.</param>
 public DuplicateArgumentException(Argument argument, string message, Exception innerException)
     : base(argument, message, innerException)
 {
 }
Example #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DuplicateArgumentException"/> class.
 /// </summary>
 /// <param name="argument">The missing argument.</param>
 /// <param name="message">The message.</param>
 public DuplicateArgumentException(Argument argument, string message)
     : base(argument, message)
 {
 }
Example #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DuplicateArgumentException"/> class.
 /// </summary>
 /// <param name="argument">The missing argument.</param>
 public DuplicateArgumentException(Argument argument)
     : base(argument, GetMessage(argument))
 {
 }
Example #6
0
        private static string GetMessage(Argument argument)
        {
            if (argument == null)
                throw new ArgumentNullException(nameof(argument));

            return Invariant($"Command line argument '{argument.Name}' must not be specified more than once. If the argument accepts several values, they must not be separated by other arguments.");
        }
Example #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandLineParserException"/> class.
 /// </summary>
 /// <param name="argument">
 /// The argument which caused the exception. Can be <see langword="null"/>.
 /// </param>
 /// <param name="message">The message.</param>
 public CommandLineParserException(Argument argument, string message)
     : base(message)
 {
     Argument = argument?.Name;
 }
Example #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MissingArgumentException"/> class.
 /// </summary>
 /// <param name="argument">The missing argument.</param>
 /// <param name="message">The message.</param>
 public MissingArgumentException(Argument argument, string message)
     : base(argument, message)
 {
 }
Example #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MissingArgumentException"/> class.
 /// </summary>
 /// <param name="argument">The missing argument.</param>
 /// <param name="message">The message.</param>
 /// <param name="innerException">The inner exception.</param>
 public MissingArgumentException(Argument argument, string message, Exception innerException)
     : base(argument, message, innerException)
 {
 }
Example #10
0
        private static string GetMessage(Argument argument)
        {
            if (argument == null)
                throw new ArgumentNullException(nameof(argument));

            return Invariant($"Mandatory command line argument '{argument.Name}' is missing.");
        }
Example #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MissingArgumentException"/> class.
 /// </summary>
 /// <param name="argument">The missing argument.</param>
 public MissingArgumentException(Argument argument)
     : base(argument, GetMessage(argument))
 {
 }
Example #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="InvalidArgumentValueException"/> class.
 /// </summary>
 /// <param name="argument">The missing argument.</param>
 /// <param name="value">The value which  could not be parsed.</param>
 /// <param name="innerException">The inner exception.</param>
 public InvalidArgumentValueException(Argument argument, string value, Exception innerException)
     : base(argument, GetMessage(argument, value), innerException)
 {
     Value = value;
 }
Example #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="InvalidArgumentValueException"/> class.
 /// </summary>
 /// <param name="argument">The missing argument.</param>
 /// <param name="message">The message.</param>
 /// <param name="value">The value which  could not be parsed.</param>
 public InvalidArgumentValueException(Argument argument, string value, string message)
     : base(argument, message)
 {
     Value = value;
 }
Example #14
0
        private static string GetMessage(Argument argument, string value)
        {
            if (argument == null)
                throw new ArgumentNullException(nameof(argument));

            return Invariant($"The value '{value}' of the command line argument '{argument.Name}' cannot be parsed.");
        }
Example #15
0
        // Remove surrounding brackets.
        private static string GetSyntaxWithoutBrackets(Argument argument)
        {
            var syntax = argument.GetSyntax();

            if (syntax == null)
                return string.Empty;

            if (syntax.StartsWith("[", StringComparison.Ordinal))
                syntax = syntax.Remove(0, 1);

            if (syntax.EndsWith("]", StringComparison.Ordinal))
                syntax = syntax.Remove(syntax.Length - 1, 1);

            return syntax;
        }
Example #16
0
        private static bool Contains(List<ArgumentResult> results, Argument argument)
        {
            foreach (var r in results)
                if (r.Argument == argument)
                    return true;

            return false;
        }