diff --git a/src/CommandLineUtils/Abstractions/ValueParserProvider.cs b/src/CommandLineUtils/Abstractions/ValueParserProvider.cs
index 1f54528d..2090a924 100644
--- a/src/CommandLineUtils/Abstractions/ValueParserProvider.cs
+++ b/src/CommandLineUtils/Abstractions/ValueParserProvider.cs
@@ -101,7 +101,7 @@ public IValueParser GetParser(Type type)
return parser;
}
- if (ReflectionHelper.IsNullableType(type, out var wrappedType) && wrappedType != null)
+ if (ReflectionHelper.IsNullableType(type, out var wrappedType))
{
if (wrappedType.IsEnum)
{
@@ -114,15 +114,9 @@ public IValueParser GetParser(Type type)
}
}
- if (!type.IsGenericType)
+ if (ReflectionHelper.IsSpecialValueTupleType(type, out var wrappedType2))
{
- return null;
- }
-
- var typeDef = type.GetGenericTypeDefinition();
- if (typeDef == typeof(ValueTuple<,>) && type.GenericTypeArguments[0] == typeof(bool))
- {
- var innerParser = GetParser(type.GenericTypeArguments[1]);
+ var innerParser = GetParser(wrappedType2);
if (innerParser == null)
{
return null;
diff --git a/src/CommandLineUtils/CommandArgument.cs b/src/CommandLineUtils/CommandArgument.cs
index e218de2f..7b2e117a 100644
--- a/src/CommandLineUtils/CommandArgument.cs
+++ b/src/CommandLineUtils/CommandArgument.cs
@@ -54,6 +54,11 @@ public CommandArgument()
///
public string? Value => Values.FirstOrDefault();
+ ///
+ /// The default value of the argument.
+ ///
+ public string? DefaultValue { get; set; }
+
///
/// A collection of validators that execute before invoking .
/// When validation fails, is invoked.
diff --git a/src/CommandLineUtils/CommandArgument{T}.cs b/src/CommandLineUtils/CommandArgument{T}.cs
index f98e0885..bc99a216 100644
--- a/src/CommandLineUtils/CommandArgument{T}.cs
+++ b/src/CommandLineUtils/CommandArgument{T}.cs
@@ -20,6 +20,7 @@ public class CommandArgument : CommandArgument, IInternalCommandParamOfT
{
private readonly List _parsedValues = new List();
private readonly IValueParser _valueParser;
+ private T _defaultValue;
///
/// Initializes a new instance of
@@ -29,6 +30,7 @@ public CommandArgument(IValueParser valueParser)
{
_valueParser = valueParser ?? throw new ArgumentNullException(nameof(valueParser));
UnderlyingType = typeof(T);
+ SetBaseDefaultValue(default);
}
///
@@ -41,6 +43,19 @@ public CommandArgument(IValueParser valueParser)
///
public IReadOnlyList ParsedValues => _parsedValues;
+ ///
+ /// The default value of the argument.
+ ///
+ public new T DefaultValue
+ {
+ get => _defaultValue;
+ set
+ {
+ _defaultValue = value;
+ SetBaseDefaultValue(value);
+ }
+ }
+
void IInternalCommandParamOfT.Parse(CultureInfo culture)
{
_parsedValues.Clear();
@@ -49,5 +64,20 @@ void IInternalCommandParamOfT.Parse(CultureInfo culture)
_parsedValues.Add(_valueParser.Parse(Name, t, culture));
}
}
+
+ void SetBaseDefaultValue(T value)
+ {
+ if (!ReflectionHelper.IsSpecialValueTupleType(typeof(T), out _))
+ {
+ if (MultipleValues && value is IEnumerable
public List Values { get; } = new List();
+ ///
+ /// The default value of the option.
+ ///
+ public string? DefaultValue { get; set; }
+
///
/// Defines the type of the option.
///
diff --git a/src/CommandLineUtils/CommandOption{T}.cs b/src/CommandLineUtils/CommandOption{T}.cs
index c52b0635..f3dcbe7a 100644
--- a/src/CommandLineUtils/CommandOption{T}.cs
+++ b/src/CommandLineUtils/CommandOption{T}.cs
@@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
+using System.Reflection;
using McMaster.Extensions.CommandLineUtils.Abstractions;
namespace McMaster.Extensions.CommandLineUtils
@@ -19,6 +20,7 @@ public class CommandOption : CommandOption, IInternalCommandParamOfT
{
private readonly List _parsedValues = new List();
private readonly IValueParser _valueParser;
+ private T _defaultValue;
///
/// Initializes a new instance of
@@ -31,6 +33,7 @@ public CommandOption(IValueParser valueParser, string template, CommandOption
{
_valueParser = valueParser ?? throw new ArgumentNullException(nameof(valueParser));
UnderlyingType = typeof(T);
+ SetBaseDefaultValue(default);
}
///
@@ -43,6 +46,19 @@ public CommandOption(IValueParser valueParser, string template, CommandOption
///
public IReadOnlyList ParsedValues => _parsedValues;
+ ///
+ /// The default value of the option.
+ ///
+ public new T DefaultValue
+ {
+ get => _defaultValue;
+ set
+ {
+ _defaultValue = value;
+ SetBaseDefaultValue(value);
+ }
+ }
+
void IInternalCommandParamOfT.Parse(CultureInfo culture)
{
_parsedValues.Clear();
@@ -51,5 +67,20 @@ void IInternalCommandParamOfT.Parse(CultureInfo culture)
_parsedValues.Add(_valueParser.Parse(LongName ?? ShortName ?? SymbolName, t, culture));
}
}
+
+ void SetBaseDefaultValue(T value)
+ {
+ if (!ReflectionHelper.IsSpecialValueTupleType(typeof(T), out _))
+ {
+ if (OptionType == CommandOptionType.MultipleValue && value is IEnumerable