Throw TypeConverterException from custom TypeConverter #2282
-
Hey im having a custom Converter who converts boolean values to localised strings:
If this conversion fails i want to throw a TypeConverterException so i can handle it along the other default conversion errors when reading using the ReadingExceptionOccurred Property of the CsvReader Configuration:
My Issue now is that im missing the CsvContext in the TypeConverter but it is needed for the TypeConverterException, otherwise the exception handler falls apart. So my question is there someway to retrieve the CsvContext in the Converter or can i throw another exceptions which gets plugged into the TypeConverterException somewhere upstream? Any other ideas? Thanks very much. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You should be able to use _ => throw new TypeConverterException(this, memberMapData, text, row.Context), Your other option would be to use csv.Context.TypeConverterOptionsCache.GetOptions<bool>().BooleanTrueValues.Add("Ja");
csv.Context.TypeConverterOptionsCache.GetOptions<bool>().BooleanFalseValues.Add("Nein");
csv.Context.TypeConverterOptionsCache.GetOptions<bool>().BooleanFalseValues.Add(""); |
Beta Was this translation helpful? Give feedback.
You should be able to use
row.Context
Your other option would be to use
TypeConverterOptionsCache
instead of theVpBoolCsvConverter