diff --git a/src/Mapster.Core/Utils/RecordTypeIdentityHelper.cs b/src/Mapster.Core/Utils/RecordTypeIdentityHelper.cs index b473802b..4e5aa197 100644 --- a/src/Mapster.Core/Utils/RecordTypeIdentityHelper.cs +++ b/src/Mapster.Core/Utils/RecordTypeIdentityHelper.cs @@ -1,9 +1,6 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Reflection; -using System.Text; -using System.Threading.Tasks; namespace Mapster.Utils { @@ -17,18 +14,18 @@ private static bool IsRecordСonstructor(Type type) { var ctors = type.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).ToList(); + if (ctors.Count < 2) + return false; + var isRecordTypeCtor = type.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic) .Where(x => x.IsFamily == true || (type.IsSealed && x.IsPrivate == true)) // add target from Sealed record .Any(x => x.GetParameters() .Any(y => y.ParameterType == type)); - - if (ctors.Count >= 2 && isRecordTypeCtor) + if (isRecordTypeCtor) return true; - return false; - } private static bool IsIncludedRecordCloneMethod(Type type) @@ -44,9 +41,7 @@ public static bool IsRecordType(Type type) if (IsRecordСonstructor(type) && IsIncludedRecordCloneMethod(type)) return true; - return false; } - } } diff --git a/src/Mapster.Tests/WhenMappingRecordRegression.cs b/src/Mapster.Tests/WhenMappingRecordRegression.cs index e22f85b1..f5ef6add 100644 --- a/src/Mapster.Tests/WhenMappingRecordRegression.cs +++ b/src/Mapster.Tests/WhenMappingRecordRegression.cs @@ -221,7 +221,6 @@ TestClassPublicCtr SomemapWithDynamic(object source) public void ImplicitOperatorCurrentWorkFromClass() { var guid = Guid.NewGuid(); - var pocoWithGuid1 = new PocoWithGuid { Id = guid }; var pocoWithId2 = new PocoWithId { Id = new Id(guid) }; @@ -231,7 +230,6 @@ public void ImplicitOperatorCurrentWorkFromClass() pocoWithId1.Id.ToString().Equals(guid.ToString()).ShouldBeTrue(); pocoWithGuid2.Id.Equals(guid).ShouldBeTrue(); - var _result = pocoWithId1.Adapt(pocoWithGuid2); _result.Id.ToString().Equals(guid.ToString()).ShouldBeTrue(); // Guid value transmitted @@ -240,8 +238,6 @@ public void ImplicitOperatorCurrentWorkFromClass() } - #region NowNotWorking - [TestMethod] public void DetectFakeRecord() { @@ -252,6 +248,8 @@ public void DetectFakeRecord() object.ReferenceEquals(_destination, _result).ShouldBeTrue(); } + #region NowNotWorking + /// /// https://github.com/MapsterMapper/Mapster/issues/430 /// @@ -313,7 +311,6 @@ class PocoWithId class Id { private readonly Guid _guid; - public Id(Guid id) => _guid = id; public static implicit operator Id(Guid value) => new(value);