diff --git a/src/CsvHelper/Configuration/ClassMapCollection.cs b/src/CsvHelper/Configuration/ClassMapCollection.cs index 21f6c17aa..93c3828ef 100644 --- a/src/CsvHelper/Configuration/ClassMapCollection.cs +++ b/src/CsvHelper/Configuration/ClassMapCollection.cs @@ -162,7 +162,7 @@ private void SetMapDefaults(ClassMap map) continue; } - if (memberMap.Data.TypeConverter == null) + if (memberMap.Data.TypeConverter == null && memberMap.Data.ReadingConvertExpression == null && memberMap.Data.WritingConvertExpression == null) { memberMap.Data.TypeConverter = context.TypeConverterCache.GetConverter(memberMap.Data.Member.MemberType()); } diff --git a/tests/CsvHelper.Tests/Configuration/CsvClassMapCollectionTests.cs b/tests/CsvHelper.Tests/Configuration/CsvClassMapCollectionTests.cs index 0a4764074..d93b22c3c 100644 --- a/tests/CsvHelper.Tests/Configuration/CsvClassMapCollectionTests.cs +++ b/tests/CsvHelper.Tests/Configuration/CsvClassMapCollectionTests.cs @@ -5,6 +5,8 @@ using CsvHelper.Configuration; using Xunit; using System.Globalization; +using System.Collections; +using System; namespace CsvHelper.Tests.Configuration { @@ -25,6 +27,17 @@ public void GetChildMapWhenParentIsMappedBeforeIt() Assert.Equal(childMap, map); } + [Fact] + public void Add_Enumerable_HasConvertSet_DoesNotAssignTypeConverter() + { + var context = new CsvContext(new CsvConfiguration(CultureInfo.InvariantCulture)); + var collection = new ClassMapCollection(context); + + var map = new EnumerablePropertyClassMap(); + collection.Add(map); + Assert.Null(map.MemberMaps.Find(m => m.Enumerable).Data.TypeConverter); + } + private class Parent { } private class Child : Parent { } @@ -32,5 +45,26 @@ private class Child : Parent { } private sealed class ParentMap : ClassMap { } private sealed class ChildMap : ClassMap { } + + private class EnumerablePropertyClass + { + public Enumerable Enumerable { get; set; } + } + + private class EnumerablePropertyClassMap : ClassMap + { + public EnumerablePropertyClassMap() + { + Map(m => m.Enumerable).Convert(_ => new Enumerable()); + } + } + + private class Enumerable : IEnumerable + { + public IEnumerator GetEnumerator() + { + throw new NotSupportedException(); + } + } } }