Skip to content

Commit

Permalink
ReflectionUtils.IsPoco does not check for IEnumerable.
Browse files Browse the repository at this point in the history
  • Loading branch information
satano committed Sep 27, 2017
1 parent aa612fd commit 8247931
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/Mapster.Tests/Mapster.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
<Compile Include="WhenMappingComplexClasses.cs" />
<Compile Include="WhenMappingDerived.cs" />
<Compile Include="WhenMappingArrays.cs" />
<Compile Include="WhenMappingIEnumerableClass.cs" />
<Compile Include="WhenMappingPrivateFieldsAndProperties.cs" />
<Compile Include="WhenMappingWithDictionary.cs" />
<Compile Include="WhenMappingRecordTypes.cs" />
Expand Down
40 changes: 40 additions & 0 deletions src/Mapster.Tests/WhenMappingIEnumerableClass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Shouldly;
using System;
using System.Collections;

namespace Mapster.Tests
{
[TestClass]
public class WhenMappingIEnumerableClasses
{
public class ClassA
{
public int Id { get; set; }
}

public class ClassB : IEnumerable
{

public int Id { get; set; }

public IEnumerator GetEnumerator()
{
throw new NotImplementedException();
}
}

[TestMethod]
public void Map_To_IEnumerable_Class_Should_Pass()
{
ClassA classA = new ClassA()
{
Id = 123
};

ClassB classB = classA.Adapt<ClassB>();
classB.Id.ShouldBe(classA.Id);
}

}
}
4 changes: 0 additions & 4 deletions src/Mapster/Utils/ReflectionUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ public static bool IsNullable(this Type type)

public static bool IsPoco(this Type type, BindingFlags accessorFlags = BindingFlags.Public)
{
//not collection
if (type.IsCollection())
return false;

//not nullable
if (type.IsNullable())
return false;
Expand Down

0 comments on commit 8247931

Please sign in to comment.