From 8d6bb0c9763fb68bed15d54cd959414670d55e14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stano=20Pe=C5=A5ko?= Date: Thu, 28 Sep 2017 18:25:54 +0200 Subject: [PATCH] Fixed NullReferenceException in ReflectionUtils.IsRecordType, fixed back mapping IEnumerable classes. --- src/Mapster.Tests/WhenMappingIEnumerableClass.cs | 3 +-- src/Mapster/Utils/ReflectionUtils.cs | 10 +--------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/Mapster.Tests/WhenMappingIEnumerableClass.cs b/src/Mapster.Tests/WhenMappingIEnumerableClass.cs index 71a0b11b..5cd2f46b 100644 --- a/src/Mapster.Tests/WhenMappingIEnumerableClass.cs +++ b/src/Mapster.Tests/WhenMappingIEnumerableClass.cs @@ -15,7 +15,6 @@ public class ClassA public class ClassB : IEnumerable { - public int Id { get; set; } public IEnumerator GetEnumerator() @@ -24,7 +23,7 @@ public IEnumerator GetEnumerator() } } - [TestMethod, Ignore] + [TestMethod] public void Map_To_IEnumerable_Class_Should_Pass() { ClassA classA = new ClassA() diff --git a/src/Mapster/Utils/ReflectionUtils.cs b/src/Mapster/Utils/ReflectionUtils.cs index b38711df..db8a58f0 100644 --- a/src/Mapster/Utils/ReflectionUtils.cs +++ b/src/Mapster/Utils/ReflectionUtils.cs @@ -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; @@ -169,10 +165,6 @@ public static bool IsReferenceAssignableFrom(this Type destType, Type srcType) public static bool IsRecordType(this Type type) { - //not collection - if (type.IsCollection()) - return false; - //not nullable if (type.IsNullable()) return false; @@ -195,7 +187,7 @@ public static bool IsRecordType(this Type type) return props.All(prop => { var name = prop.Name.ToPascalCase(); - return ctors[0].GetParameters().Any(p => p.ParameterType == prop.Type && p.Name.ToPascalCase() == name); + return ctors[0].GetParameters().Any(p => p.ParameterType == prop.Type && p.Name?.ToPascalCase() == name); }); }