mirror of
				https://github.com/nsnail/spectre.console.git
				synced 2025-11-01 01:25:27 +08:00 
			
		
		
		
	Fix type conversion in the default pair deconstructor implementation (#618)
The code using the TypeConverter was written backwards (using `ConvertTo` instead of `ConvertFrom` and would thus throw an exception.
This commit is contained in:
		| @@ -19,9 +19,6 @@ namespace Spectre.Console.Cli | ||||
|                 throw new ArgumentNullException(nameof(value)); | ||||
|             } | ||||
|  | ||||
|             var keyConverter = GetConverter(keyType); | ||||
|             var valueConverter = GetConverter(valueType); | ||||
|  | ||||
|             var parts = value.Split(new[] { '=' }, StringSplitOptions.None); | ||||
|             if (parts.Length < 1 || parts.Length > 2) | ||||
|             { | ||||
| @@ -47,15 +44,16 @@ namespace Spectre.Console.Cli | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             return (Parse(keyConverter, keyType, stringkey), | ||||
|                 Parse(valueConverter, valueType, stringValue)); | ||||
|             return (Parse(stringkey, keyType), | ||||
|                 Parse(stringValue, valueType)); | ||||
|         } | ||||
|  | ||||
|         private static object Parse(TypeConverter converter, Type type, string value) | ||||
|         private static object? Parse(string value, Type targetType) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 return converter.ConvertTo(value, type); | ||||
|                 var converter = GetConverter(targetType); | ||||
|                 return converter.ConvertFrom(value); | ||||
|             } | ||||
|             catch | ||||
|             { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Cédric Luthi
					Cédric Luthi