public object ConvertValue(Type convertToType, IReadOnlyList <string> rawValues)
        {
            var converterStack = _typeConverters;

            while (converterStack.IsEmpty == false)
            {
                ITypeConverter converter;
                (converter, converterStack) = converterStack.Pop();

                if (TryConvertValue(converter, convertToType, rawValues, out var result))
                {
                    if (ResultIsOfCorrectType(convertToType, result))
                    {
                        return(result);
                    }
                    else
                    {
                        throw new TypeConversionException(
                                  TypeConversionException.ATypeConverterReturnedAnIncorrectValue(
                                      rawValues, convertToType, result, converter));
                    }
                }
            }

            throw new TypeConversionException(
                      TypeConversionException.NoTypeConvertersCouldConvertValue(rawValues, convertToType));
        }
 public bool TryConvertValue(
     Type convertToType,
     IReadOnlyList <string> rawValues,
     [AllowNull] out object convertedValue)
 {
     if (TryGetCompatibleConstructor(convertToType, rawValues.Count).IsSome(out var constructor))
     {
         try
         {
             convertedValue = constructor.Invoke(rawValues.ToArray());
             return(true);
         }
         catch (TargetInvocationException e)
         {
             throw new TypeConversionException(
                       TypeConversionException.TheConstructorForTypeXThrewAnException(convertToType, rawValues),
                       e.InnerException);
         }
     }
     else
     {
         convertedValue = null;
         return(false);
     }
 }