Skip to content

Commit

Permalink
refactoring and
Browse files Browse the repository at this point in the history
del empty lines
  • Loading branch information
DocSvartz committed Oct 15, 2023
1 parent 531f0ed commit f678d12
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
13 changes: 4 additions & 9 deletions src/Mapster.Core/Utils/RecordTypeIdentityHelper.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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)
Expand All @@ -44,9 +41,7 @@ public static bool IsRecordType(Type type)
if (IsRecordСonstructor(type) && IsIncludedRecordCloneMethod(type))
return true;


return false;
}

}
}
7 changes: 2 additions & 5 deletions src/Mapster.Tests/WhenMappingRecordRegression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) };

Expand All @@ -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
Expand All @@ -240,8 +238,6 @@ public void ImplicitOperatorCurrentWorkFromClass()

}

#region NowNotWorking

[TestMethod]
public void DetectFakeRecord()
{
Expand All @@ -252,6 +248,8 @@ public void DetectFakeRecord()
object.ReferenceEquals(_destination, _result).ShouldBeTrue();
}

#region NowNotWorking

/// <summary>
/// https://github.com/MapsterMapper/Mapster/issues/430
/// </summary>
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f678d12

Please sign in to comment.