@@ -37,7 +37,8 @@ internal static class ArgumentConverter
3737 internal static ArgumentConversionResult ConvertObject (
3838 IArgument argument ,
3939 Type type ,
40- object ? value )
40+ object ? value ,
41+ Resources resources )
4142 {
4243 if ( argument . Arity . MaximumNumberOfValues == 0 )
4344 {
@@ -49,15 +50,15 @@ internal static ArgumentConversionResult ConvertObject(
4950 case string singleValue :
5051 if ( type . IsEnumerable ( ) && ! type . HasStringTypeConverter ( ) )
5152 {
52- return ConvertStrings ( argument , type , new [ ] { singleValue } ) ;
53+ return ConvertStrings ( argument , type , new [ ] { singleValue } , resources ) ;
5354 }
5455 else
5556 {
56- return ConvertString ( argument , type , singleValue ) ;
57+ return ConvertString ( argument , type , singleValue , resources ) ;
5758 }
5859
5960 case IReadOnlyList < string > manyValues :
60- return ConvertStrings ( argument , type , manyValues ) ;
61+ return ConvertStrings ( argument , type , manyValues , resources ) ;
6162 }
6263
6364 return None ( argument ) ;
@@ -66,7 +67,8 @@ internal static ArgumentConversionResult ConvertObject(
6667 private static ArgumentConversionResult ConvertString (
6768 IArgument argument ,
6869 Type ? type ,
69- string value )
70+ string value ,
71+ Resources resources )
7072 {
7173 type ??= typeof ( string ) ;
7274
@@ -82,7 +84,7 @@ private static ArgumentConversionResult ConvertString(
8284 }
8385 catch ( Exception )
8486 {
85- return Failure ( argument , type , value ) ;
87+ return Failure ( argument , type , value , resources ) ;
8688 }
8789 }
8890 }
@@ -105,13 +107,14 @@ private static ArgumentConversionResult ConvertString(
105107 return Success ( argument , instance ) ;
106108 }
107109
108- return Failure ( argument , type , value ) ;
110+ return Failure ( argument , type , value , resources ) ;
109111 }
110112
111113 public static ArgumentConversionResult ConvertStrings (
112114 IArgument argument ,
113115 Type type ,
114116 IReadOnlyList < string > tokens ,
117+ Resources resources ,
115118 ArgumentResult ? argumentResult = null )
116119 {
117120 Type itemType ;
@@ -137,7 +140,7 @@ public static ArgumentConversionResult ConvertStrings(
137140 {
138141 var token = tokens [ i ] ;
139142
140- var result = ConvertString ( argument , itemType , token ) ;
143+ var result = ConvertString ( argument , itemType , token , resources ) ;
141144
142145 switch ( result )
143146 {
@@ -204,9 +207,10 @@ internal static bool HasStringTypeConverter(this Type type) =>
204207 private static FailedArgumentConversionResult Failure (
205208 IArgument argument ,
206209 Type expectedType ,
207- string value )
210+ string value ,
211+ Resources resources )
208212 {
209- return new FailedArgumentTypeConversionResult ( argument , expectedType , value ) ;
213+ return new FailedArgumentTypeConversionResult ( argument , expectedType , value , resources ) ;
210214 }
211215
212216 internal static ArgumentConversionResult ConvertIfNeeded (
@@ -219,19 +223,21 @@ internal static ArgumentConversionResult ConvertIfNeeded(
219223 SuccessfulArgumentConversionResult successful when ! toType . IsInstanceOfType ( successful . Value ) =>
220224 ConvertObject ( conversionResult . Argument ,
221225 toType ,
222- successful . Value ) ,
226+ successful . Value ,
227+ symbolResult . Resources ) ,
223228 SuccessfulArgumentConversionResult successful when toType == typeof ( object ) &&
224229 conversionResult . Argument . Arity . MaximumNumberOfValues > 1 &&
225230 successful . Value is string =>
226231 ConvertObject ( conversionResult . Argument ,
227232 typeof ( IEnumerable < string > ) ,
228- successful . Value ) ,
233+ successful . Value ,
234+ symbolResult . Resources ) ,
229235 NoArgumentConversionResult _ when toType == typeof ( bool ) =>
230236 Success ( conversionResult . Argument ,
231237 true ) ,
232238 NoArgumentConversionResult _ when conversionResult . Argument . Arity . MinimumNumberOfValues > 0 =>
233239 new MissingArgumentConversionResult ( conversionResult . Argument ,
234- Resources . Instance . RequiredArgumentMissing ( symbolResult ) ) ,
240+ symbolResult . Resources . RequiredArgumentMissing ( symbolResult ) ) ,
235241 NoArgumentConversionResult _ when conversionResult . Argument . Arity . MaximumNumberOfValues > 1 =>
236242 Success ( conversionResult . Argument ,
237243 Array . Empty < string > ( ) ) ,
@@ -274,8 +280,8 @@ public static bool TryConvertArgument(ArgumentResult argumentResult, out object?
274280 {
275281 // 0 is an implicit bool, i.e. a "flag"
276282 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 )
279285 } ;
280286
281287 return value is SuccessfulArgumentConversionResult ;
0 commit comments