File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22using Shouldly ;
33using System ;
44using System . Collections . Generic ;
5+ using System . Globalization ;
56using System . Text . Json ;
67using static Mapster . Tests . WhenExplicitMappingRequired ;
78using static Mapster . Tests . WhenMappingDerived ;
@@ -562,6 +563,23 @@ public void NotSelfCreationTypeMappingInContainingClassWithoutError()
562563 uriDest . Uri . ToString ( ) . ShouldBe ( "https://www.google.com/" ) ;
563564 }
564565
566+ /// <summary>
567+ /// https://github.com/MapsterMapper/Mapster/issues/995
568+ /// </summary>
569+ [ TestMethod ]
570+ public void TypeWithOutPublicCtorDetectAsNotSelfCreationType ( )
571+ {
572+ var src = new CultureInfo ( "fr-FR" ) ;
573+
574+ Should . NotThrow ( ( ) =>
575+ {
576+ //src.Adapt<CultureInfo>();
577+ src . TextInfo . Adapt < TextInfo > ( ) ;
578+ } ) ;
579+
580+ }
581+
582+
565583 class SourceClassWithJsonDocument911
566584 {
567585 public required JsonDocument Json { get ; init ; }
Original file line number Diff line number Diff line change @@ -460,9 +460,11 @@ public static bool IsNotSelfCreation(this Type type)
460460 return false ;
461461 if ( type . IsCollectionCompatible ( ) )
462462 return false ;
463-
463+ if ( type . GetConstructors ( ) . Length == 0 )
464+ return true ;
464465 if ( type == typeof ( Type ) || type . BaseType == typeof ( MulticastDelegate ) )
465466 return true ;
467+
466468
467469 return type . GetFieldsAndProperties ( ) . All ( it => ( it . SetterModifier & ( AccessModifier . Public | AccessModifier . NonPublic ) ) == 0 ) ;
468470 }
You can’t perform that action at this time.
0 commit comments