Skip to content

Commit

Permalink
Merge branch 'MiblaCz-bugfix-2081-generic-types-error'
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshClose committed Jan 25, 2024
2 parents 2b3ca3b + 16bf2b0 commit 644a570
Showing 1 changed file with 38 additions and 38 deletions.
76 changes: 38 additions & 38 deletions src/CsvHelper/TypeConversion/CollectionConverterFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace CsvHelper.TypeConversion
{
Expand Down Expand Up @@ -118,48 +115,51 @@ public bool Create(Type type, TypeConverterCache cache, out ITypeConverter typeC
}

var isGenericType = type.GetTypeInfo().IsGenericType;
var genericTypeDefinition = type.GetGenericTypeDefinition();

if (isGenericType && genericTypeDefinition == typeof(Dictionary<,>))
if (isGenericType)
{
typeConverter = new IDictionaryGenericConverter();
return true;
}
var genericTypeDefinition = type.GetGenericTypeDefinition();

if (isGenericType && genericTypeDefinition == typeof(IDictionary<,>))
{
typeConverter = new IDictionaryGenericConverter();
return true;
}
if (genericTypeDefinition == typeof(Dictionary<,>))
{
typeConverter = new IDictionaryGenericConverter();
return true;
}

if (isGenericType && genericTypeDefinition == typeof(List<>))
{
typeConverter = new CollectionGenericConverter();
return true;
}
if (genericTypeDefinition == typeof(IDictionary<,>))
{
typeConverter = new IDictionaryGenericConverter();
return true;
}

if (isGenericType && genericTypeDefinition == typeof(Collection<>))
{
typeConverter = new CollectionGenericConverter();
return true;
}
if (genericTypeDefinition == typeof(List<>))
{
typeConverter = new CollectionGenericConverter();
return true;
}

if (isGenericType && genericTypeDefinition == typeof(IList<>))
{
typeConverter = new IEnumerableGenericConverter();
return true;
}
if (genericTypeDefinition == typeof(Collection<>))
{
typeConverter = new CollectionGenericConverter();
return true;
}

if (isGenericType && genericTypeDefinition == typeof(ICollection<>))
{
typeConverter = new IEnumerableGenericConverter();
return true;
}
if (genericTypeDefinition == typeof(IList<>))
{
typeConverter = new IEnumerableGenericConverter();
return true;
}

if (isGenericType && genericTypeDefinition == typeof(IEnumerable<>))
{
typeConverter = new IEnumerableGenericConverter();
return true;
if (genericTypeDefinition == typeof(ICollection<>))
{
typeConverter = new IEnumerableGenericConverter();
return true;
}

if (genericTypeDefinition == typeof(IEnumerable<>))
{
typeConverter = new IEnumerableGenericConverter();
return true;
}
}

// A specific IEnumerable converter doesn't exist.
Expand Down

0 comments on commit 644a570

Please sign in to comment.