Skip to content

Commit

Permalink
refactor (dummy) Type-TypeConverter to NotSupportedTypeConverter<Type>
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBertels committed Feb 9, 2024
1 parent f1e2bfc commit 0b2d22c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace CsvHelper.TypeConversion
/// converter will need to be created to have a field convert to and
/// from <see cref="Type"/>.
/// </summary>
public class TypeConverter : DefaultTypeConverter
public class NotSupportedTypeConverter<T> : TypeConverterGeneric<T>
{
/// <summary>
/// Throws an exception.
Expand All @@ -26,9 +26,9 @@ public class TypeConverter : DefaultTypeConverter
/// <param name="row">The <see cref="IReaderRow"/> for the current record.</param>
/// <param name="memberMapData">The <see cref="MemberMapData"/> for the member being created.</param>
/// <returns>The object created from the string.</returns>
public override object ConvertFromString(string text, IReaderRow row, MemberMapData memberMapData)
public override T ConvertFromString(string text, IReaderRow row, MemberMapData memberMapData)
{
var message = "Converting System.Type is not supported. " +
var message = $"Converting " + typeof(T).FullName + " is not supported. " +
"If you want to do this, create your own ITypeConverter and register " +
"it in the TypeConverterFactory by calling AddConverter.";
throw new TypeConverterException(this, memberMapData, text ?? string.Empty, row.Context, message);
Expand All @@ -41,9 +41,9 @@ public override object ConvertFromString(string text, IReaderRow row, MemberMapD
/// <param name="row">The <see cref="IWriterRow"/> for the current record.</param>
/// <param name="memberMapData">The <see cref="MemberMapData"/> for the member being written.</param>
/// <returns>The string representation of the object.</returns>
public override string ConvertToString(object value, IWriterRow row, MemberMapData memberMapData)
public override string ConvertToString(T value, IWriterRow row, MemberMapData memberMapData)
{
var message = "Converting System.Type is not supported. " +
var message = "Converting " + typeof(T).FullName + " is not supported. " +
"If you want to do this, create your own ITypeConverter and register " +
"it in the TypeConverterFactory by calling AddConverter.";
throw new TypeConverterException(this, memberMapData, value, row.Context, message);
Expand Down
2 changes: 1 addition & 1 deletion src/CsvHelper/TypeConversion/TypeConverterCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ private void CreateDefaultConverters()
AddConverter(typeof(sbyte), new SByteConverter());
AddConverter(typeof(string), new StringConverter());
AddConverter(typeof(TimeSpan), new TimeSpanConverter());
AddConverter(typeof(Type), new TypeConverter());
AddConverter(new NotSupportedTypeConverter<Type>());
AddConverter(typeof(ushort), new UInt16Converter());
AddConverter(typeof(uint), new UInt32Converter());
AddConverter(typeof(ulong), new UInt64Converter());
Expand Down

0 comments on commit 0b2d22c

Please sign in to comment.