Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/Mapster.Tests/WhenMappingRecordRegression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Shouldly;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text.Json;
using static Mapster.Tests.WhenExplicitMappingRequired;
using static Mapster.Tests.WhenMappingDerived;
Expand Down Expand Up @@ -562,6 +563,23 @@ public void NotSelfCreationTypeMappingInContainingClassWithoutError()
uriDest.Uri.ToString().ShouldBe("https://www.google.com/");
}

/// <summary>
/// https://github.com/MapsterMapper/Mapster/issues/995
/// </summary>
[TestMethod]
public void TypeWithOutPublicCtorDetectAsNotSelfCreationType()
{
var src = new CultureInfo("fr-FR");

Should.NotThrow(()=>
{
//src.Adapt<CultureInfo>();
src.TextInfo.Adapt<TextInfo>();
});

}


class SourceClassWithJsonDocument911
{
public required JsonDocument Json { get; init; }
Expand Down
4 changes: 3 additions & 1 deletion src/Mapster/Utils/ReflectionUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,11 @@ public static bool IsNotSelfCreation(this Type type)
return false;
if(type.IsCollectionCompatible())
return false;

if (type.GetConstructors().Length == 0)
return true;
if (type == typeof(Type) || type.BaseType == typeof(MulticastDelegate))
return true;


return type.GetFieldsAndProperties().All(it => (it.SetterModifier & (AccessModifier.Public | AccessModifier.NonPublic)) == 0);
}
Expand Down
Loading