2
2
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3
3
4
4
using System ;
5
+ using System . Collections ;
6
+ using System . Collections . Generic ;
5
7
using System . ComponentModel . DataAnnotations ;
6
8
using System . Linq ;
7
9
using System . Reflection ;
@@ -57,6 +59,7 @@ private protected void AddOption(ConventionContext context, CommandOption option
57
59
context . Application . _longOptions . Add ( option . LongName , prop ) ;
58
60
}
59
61
62
+ var getter = ReflectionHelper . GetPropertyGetter ( prop ) ;
60
63
var setter = ReflectionHelper . GetPropertySetter ( prop ) ;
61
64
62
65
switch ( option . OptionType )
@@ -71,9 +74,19 @@ private protected void AddOption(ConventionContext context, CommandOption option
71
74
{
72
75
if ( ! option . HasValue ( ) )
73
76
{
74
- return ;
77
+ if ( ! ReflectionHelper . IsSpecialValueTupleType ( prop . PropertyType , out var type ) )
78
+ {
79
+ if ( getter . Invoke ( modelAccessor . GetModel ( ) ) is IEnumerable < object > value )
80
+ {
81
+ option . Values . AddRange ( value . Select ( x => x ? . ToString ( ) ) ) ;
82
+ option . DefaultValue = string . Join ( ", " , value . Select ( x => x ? . ToString ( ) ) ) ;
83
+ }
84
+ }
85
+ }
86
+ else
87
+ {
88
+ setter . Invoke ( modelAccessor . GetModel ( ) , collectionParser . Parse ( option . LongName , option . Values ) ) ;
75
89
}
76
- setter . Invoke ( modelAccessor . GetModel ( ) , collectionParser . Parse ( option . LongName , option . Values ) ) ;
77
90
} ) ;
78
91
break ;
79
92
case CommandOptionType . SingleOrNoValue :
@@ -87,9 +100,21 @@ private protected void AddOption(ConventionContext context, CommandOption option
87
100
{
88
101
if ( ! option . HasValue ( ) )
89
102
{
90
- return ;
103
+ if ( ! ReflectionHelper . IsSpecialValueTupleType ( prop . PropertyType , out var type ) )
104
+ {
105
+ var value = getter . Invoke ( modelAccessor . GetModel ( ) ) ;
106
+
107
+ if ( value != null )
108
+ {
109
+ option . Values . Add ( value . ToString ( ) ) ;
110
+ option . DefaultValue = value . ToString ( ) ;
111
+ }
112
+ }
113
+ }
114
+ else
115
+ {
116
+ setter . Invoke ( modelAccessor . GetModel ( ) , parser . Parse ( option . LongName , option . Value ( ) , context . Application . ValueParsers . ParseCulture ) ) ;
91
117
}
92
- setter . Invoke ( modelAccessor . GetModel ( ) , parser . Parse ( option . LongName , option . Value ( ) , context . Application . ValueParsers . ParseCulture ) ) ;
93
118
} ) ;
94
119
break ;
95
120
case CommandOptionType . NoValue :
0 commit comments