@@ -37,7 +37,8 @@ internal static class ArgumentConverter
37
37
internal static ArgumentConversionResult ConvertObject (
38
38
IArgument argument ,
39
39
Type type ,
40
- object ? value )
40
+ object ? value ,
41
+ Resources resources )
41
42
{
42
43
if ( argument . Arity . MaximumNumberOfValues == 0 )
43
44
{
@@ -49,15 +50,15 @@ internal static ArgumentConversionResult ConvertObject(
49
50
case string singleValue :
50
51
if ( type . IsEnumerable ( ) && ! type . HasStringTypeConverter ( ) )
51
52
{
52
- return ConvertStrings ( argument , type , new [ ] { singleValue } ) ;
53
+ return ConvertStrings ( argument , type , new [ ] { singleValue } , resources ) ;
53
54
}
54
55
else
55
56
{
56
- return ConvertString ( argument , type , singleValue ) ;
57
+ return ConvertString ( argument , type , singleValue , resources ) ;
57
58
}
58
59
59
60
case IReadOnlyList < string > manyValues :
60
- return ConvertStrings ( argument , type , manyValues ) ;
61
+ return ConvertStrings ( argument , type , manyValues , resources ) ;
61
62
}
62
63
63
64
return None ( argument ) ;
@@ -66,7 +67,8 @@ internal static ArgumentConversionResult ConvertObject(
66
67
private static ArgumentConversionResult ConvertString (
67
68
IArgument argument ,
68
69
Type ? type ,
69
- string value )
70
+ string value ,
71
+ Resources resources )
70
72
{
71
73
type ??= typeof ( string ) ;
72
74
@@ -82,7 +84,7 @@ private static ArgumentConversionResult ConvertString(
82
84
}
83
85
catch ( Exception )
84
86
{
85
- return Failure ( argument , type , value ) ;
87
+ return Failure ( argument , type , value , resources ) ;
86
88
}
87
89
}
88
90
}
@@ -105,13 +107,14 @@ private static ArgumentConversionResult ConvertString(
105
107
return Success ( argument , instance ) ;
106
108
}
107
109
108
- return Failure ( argument , type , value ) ;
110
+ return Failure ( argument , type , value , resources ) ;
109
111
}
110
112
111
113
public static ArgumentConversionResult ConvertStrings (
112
114
IArgument argument ,
113
115
Type type ,
114
116
IReadOnlyList < string > tokens ,
117
+ Resources resources ,
115
118
ArgumentResult ? argumentResult = null )
116
119
{
117
120
Type itemType ;
@@ -137,7 +140,7 @@ public static ArgumentConversionResult ConvertStrings(
137
140
{
138
141
var token = tokens [ i ] ;
139
142
140
- var result = ConvertString ( argument , itemType , token ) ;
143
+ var result = ConvertString ( argument , itemType , token , resources ) ;
141
144
142
145
switch ( result )
143
146
{
@@ -204,9 +207,10 @@ internal static bool HasStringTypeConverter(this Type type) =>
204
207
private static FailedArgumentConversionResult Failure (
205
208
IArgument argument ,
206
209
Type expectedType ,
207
- string value )
210
+ string value ,
211
+ Resources resources )
208
212
{
209
- return new FailedArgumentTypeConversionResult ( argument , expectedType , value ) ;
213
+ return new FailedArgumentTypeConversionResult ( argument , expectedType , value , resources ) ;
210
214
}
211
215
212
216
internal static ArgumentConversionResult ConvertIfNeeded (
@@ -219,19 +223,21 @@ internal static ArgumentConversionResult ConvertIfNeeded(
219
223
SuccessfulArgumentConversionResult successful when ! toType . IsInstanceOfType ( successful . Value ) =>
220
224
ConvertObject ( conversionResult . Argument ,
221
225
toType ,
222
- successful . Value ) ,
226
+ successful . Value ,
227
+ symbolResult . Resources ) ,
223
228
SuccessfulArgumentConversionResult successful when toType == typeof ( object ) &&
224
229
conversionResult . Argument . Arity . MaximumNumberOfValues > 1 &&
225
230
successful . Value is string =>
226
231
ConvertObject ( conversionResult . Argument ,
227
232
typeof ( IEnumerable < string > ) ,
228
- successful . Value ) ,
233
+ successful . Value ,
234
+ symbolResult . Resources ) ,
229
235
NoArgumentConversionResult _ when toType == typeof ( bool ) =>
230
236
Success ( conversionResult . Argument ,
231
237
true ) ,
232
238
NoArgumentConversionResult _ when conversionResult . Argument . Arity . MinimumNumberOfValues > 0 =>
233
239
new MissingArgumentConversionResult ( conversionResult . Argument ,
234
- Resources . Instance . RequiredArgumentMissing ( symbolResult ) ) ,
240
+ symbolResult . Resources . RequiredArgumentMissing ( symbolResult ) ) ,
235
241
NoArgumentConversionResult _ when conversionResult . Argument . Arity . MaximumNumberOfValues > 1 =>
236
242
Success ( conversionResult . Argument ,
237
243
Array . Empty < string > ( ) ) ,
@@ -274,8 +280,8 @@ public static bool TryConvertArgument(ArgumentResult argumentResult, out object?
274
280
{
275
281
// 0 is an implicit bool, i.e. a "flag"
276
282
0 => Success ( argumentResult . Argument , true ) ,
277
- 1 => ConvertObject ( argument , argument . ValueType , argumentResult . Tokens [ 0 ] . Value ) ,
278
- _ => ConvertStrings ( argument , argument . ValueType , argumentResult . Tokens . Select ( t => t . Value ) . ToArray ( ) , argumentResult )
283
+ 1 => ConvertObject ( argument , argument . ValueType , argumentResult . Tokens [ 0 ] . Value , argumentResult . Resources ) ,
284
+ _ => ConvertStrings ( argument , argument . ValueType , argumentResult . Tokens . Select ( t => t . Value ) . ToArray ( ) , argumentResult . Resources , argumentResult )
279
285
} ;
280
286
281
287
return value is SuccessfulArgumentConversionResult ;
0 commit comments