@@ -538,13 +538,13 @@ private object FromDynamoDBEntry(SimplePropertyStorage propertyStorage, DynamoDB
538
538
Document document = entry as Document ;
539
539
if ( document != null )
540
540
{
541
- if ( TryFromMap ( targetType , document , flatConfig , propertyStorage . DerivedTypeKeysDictionary , out output ) )
541
+ if ( TryFromMap ( targetType , document , flatConfig , propertyStorage , out output ) )
542
542
return output ;
543
543
544
544
var typeAttributeName = flatConfig . DerivedTypeAttributeName ; //"$type";
545
545
var derivedType = document . ContainsKey ( typeAttributeName ) ? document [ typeAttributeName ] . AsString ( ) : null ;
546
546
547
- if ( derivedType != null && propertyStorage . DerivedTypeKeysDictionary . TryGetValue ( derivedType , out var value ) )
547
+ if ( derivedType != null && propertyStorage . TryGetDerivedType ( derivedType , out var value ) )
548
548
{
549
549
targetType = value ;
550
550
}
@@ -554,7 +554,7 @@ private object FromDynamoDBEntry(SimplePropertyStorage propertyStorage, DynamoDB
554
554
555
555
DynamoDBList list = entry as DynamoDBList ;
556
556
if ( list != null &&
557
- TryFromList ( targetType , list , flatConfig , propertyStorage . DerivedTypeKeysDictionary , out output ) )
557
+ TryFromList ( targetType , list , flatConfig , propertyStorage , out output ) )
558
558
{
559
559
return output ;
560
560
}
@@ -565,17 +565,17 @@ private object FromDynamoDBEntry(SimplePropertyStorage propertyStorage, DynamoDB
565
565
}
566
566
}
567
567
private bool TryFromList ( [ DynamicallyAccessedMembers ( InternalConstants . DataModelModeledType ) ] Type targetType , DynamoDBList list , DynamoDBFlatConfig flatConfig ,
568
- Dictionary < string , Type > derivedTypeKeysDictionary , out object output )
568
+ SimplePropertyStorage parentPropertyStorage , out object output )
569
569
{
570
570
return targetType . IsArray ?
571
- TryFromListToArray ( targetType , list , flatConfig , derivedTypeKeysDictionary , out output ) : //targetType is Array
572
- TryFromListToIList ( targetType , list , flatConfig , derivedTypeKeysDictionary , out output ) ; //targetType is IList or has Add method.
571
+ TryFromListToArray ( targetType , list , flatConfig , parentPropertyStorage , out output ) : //targetType is Array
572
+ TryFromListToIList ( targetType , list , flatConfig , parentPropertyStorage , out output ) ; //targetType is IList or has Add method.
573
573
}
574
574
575
575
[ UnconditionalSuppressMessage ( "ReflectionAnalysis" , "IL2062" ,
576
576
Justification = "The user's type has been annotated with InternalConstants.DataModelModeledType with the public API into the library. At this point the type will not be trimmed." ) ]
577
577
578
- private bool TryFromListToIList ( [ DynamicallyAccessedMembers ( InternalConstants . DataModelModeledType ) ] Type targetType , DynamoDBList list , DynamoDBFlatConfig flatConfig , Dictionary < string , Type > derivedTypeKeysDictionary , out object output )
578
+ private bool TryFromListToIList ( [ DynamicallyAccessedMembers ( InternalConstants . DataModelModeledType ) ] Type targetType , DynamoDBList list , DynamoDBFlatConfig flatConfig , SimplePropertyStorage parentPropertyStorage , out object output )
579
579
{
580
580
if ( ( ! Utils . ImplementsInterface ( targetType , typeof ( ICollection < > ) ) &&
581
581
! Utils . ImplementsInterface ( targetType , typeof ( IList ) ) ) ||
@@ -589,7 +589,7 @@ private bool TryFromListToIList([DynamicallyAccessedMembers(InternalConstants.Da
589
589
var collection = Utils . Instantiate ( targetType ) ;
590
590
IList ilist = collection as IList ;
591
591
bool useIListInterface = ilist != null ;
592
- var propertyStorage = new SimplePropertyStorage ( elementType , derivedTypeKeysDictionary ) ;
592
+ var propertyStorage = new SimplePropertyStorage ( elementType , parentPropertyStorage ) ;
593
593
594
594
MethodInfo collectionAdd = null ;
595
595
if ( ! useIListInterface )
@@ -611,7 +611,7 @@ private bool TryFromListToIList([DynamicallyAccessedMembers(InternalConstants.Da
611
611
return true ;
612
612
}
613
613
614
- private bool TryFromListToArray ( [ DynamicallyAccessedMembers ( InternalConstants . DataModelModeledType ) ] Type targetType , DynamoDBList list , DynamoDBFlatConfig flatConfig , Dictionary < string , Type > derivedTypeKeysDictionary , out object output )
614
+ private bool TryFromListToArray ( [ DynamicallyAccessedMembers ( InternalConstants . DataModelModeledType ) ] Type targetType , DynamoDBList list , DynamoDBFlatConfig flatConfig , SimplePropertyStorage parentPropertyStorage , out object output )
615
615
{
616
616
if ( ! Utils . CanInstantiateArray ( targetType ) )
617
617
{
@@ -621,7 +621,7 @@ private bool TryFromListToArray([DynamicallyAccessedMembers(InternalConstants.Da
621
621
622
622
var elementType = Utils . GetElementType ( targetType ) ;
623
623
var array = ( Array ) Utils . InstantiateArray ( targetType , list . Entries . Count ) ;
624
- var propertyStorage = new SimplePropertyStorage ( elementType , derivedTypeKeysDictionary ) ;
624
+ var propertyStorage = new SimplePropertyStorage ( elementType , parentPropertyStorage ) ;
625
625
626
626
for ( int i = 0 ; i < list . Entries . Count ; i ++ )
627
627
{
@@ -636,7 +636,7 @@ private bool TryFromListToArray([DynamicallyAccessedMembers(InternalConstants.Da
636
636
637
637
[ UnconditionalSuppressMessage ( "ReflectionAnalysis" , "IL2067" ,
638
638
Justification = "The user's type has been annotated with InternalConstants.DataModelModeledType with the public API into the library. At this point the type will not be trimmed." ) ]
639
- private bool TryFromMap ( [ DynamicallyAccessedMembers ( InternalConstants . DataModelModeledType ) ] Type targetType , Document map , DynamoDBFlatConfig flatConfig , Dictionary < string , Type > derivedTypeKeysDictionary , out object output )
639
+ private bool TryFromMap ( [ DynamicallyAccessedMembers ( InternalConstants . DataModelModeledType ) ] Type targetType , Document map , DynamoDBFlatConfig flatConfig , SimplePropertyStorage parentPropertyStorage , out object output )
640
640
{
641
641
output = null ;
642
642
@@ -649,7 +649,7 @@ private bool TryFromMap([DynamicallyAccessedMembers(InternalConstants.DataModelM
649
649
650
650
var dictionary = Utils . Instantiate ( targetType ) ;
651
651
var idictionary = dictionary as IDictionary ;
652
- var propertyStorage = new SimplePropertyStorage ( valueType , derivedTypeKeysDictionary ) ;
652
+ var propertyStorage = new SimplePropertyStorage ( valueType , parentPropertyStorage ) ;
653
653
654
654
foreach ( var kvp in map )
655
655
{
@@ -668,6 +668,9 @@ internal DynamoDBEntry ToDynamoDBEntry(SimplePropertyStorage propertyStorage, ob
668
668
{
669
669
return ToDynamoDBEntry ( propertyStorage , value , flatConfig , canReturnScalarInsteadOfList : false ) ;
670
670
}
671
+
672
+ [ UnconditionalSuppressMessage ( "ReflectionAnalysis" , "IL2072" ,
673
+ Justification = "The user's type has been annotated with InternalConstants.DataModelModeledType with the public API into the library. At this point the type will not be trimmed." ) ]
671
674
private DynamoDBEntry ToDynamoDBEntry ( SimplePropertyStorage propertyStorage , object value , DynamoDBFlatConfig flatConfig , bool canReturnScalarInsteadOfList )
672
675
{
673
676
if ( value == null )
@@ -685,9 +688,9 @@ private DynamoDBEntry ToDynamoDBEntry(SimplePropertyStorage propertyStorage, obj
685
688
686
689
Type type ;
687
690
string typeDiscriminator = null ;
688
- if ( propertyStorage . DerivedTypesDictionary . ContainsKey ( value . GetType ( ) ) )
691
+ if ( propertyStorage . TryGetDerivedTypeDiscriminator ( value . GetType ( ) , out var td ) )
689
692
{
690
- typeDiscriminator = propertyStorage . DerivedTypesDictionary [ value . GetType ( ) ] ;
693
+ typeDiscriminator = td ;
691
694
type = value . GetType ( ) ;
692
695
}
693
696
else
@@ -707,11 +710,11 @@ private DynamoDBEntry ToDynamoDBEntry(SimplePropertyStorage propertyStorage, obj
707
710
else
708
711
{
709
712
Document map ;
710
- if ( TryToMap ( value , type , flatConfig , propertyStorage . DerivedTypesDictionary , out map ) )
713
+ if ( TryToMap ( value , type , flatConfig , propertyStorage , out map ) )
711
714
return map ;
712
715
713
716
DynamoDBList list ;
714
- if ( TryToList ( value , type , flatConfig , propertyStorage . DerivedTypesDictionary , out list ) )
717
+ if ( TryToList ( value , type , flatConfig , propertyStorage , out list ) )
715
718
return list ;
716
719
717
720
return SerializeToDocument ( value , type , flatConfig , typeDiscriminator ) ;
@@ -721,7 +724,7 @@ private DynamoDBEntry ToDynamoDBEntry(SimplePropertyStorage propertyStorage, obj
721
724
[ UnconditionalSuppressMessage ( "ReflectionAnalysis" , "IL2067" ,
722
725
Justification = "The user's type has been annotated with InternalConstants.DataModelModeledType with the public API into the library. At this point the type will not be trimmed." ) ]
723
726
private bool TryToMap ( object value , [ DynamicallyAccessedMembers ( InternalConstants . DataModelModeledType ) ] Type type , DynamoDBFlatConfig flatConfig ,
724
- Dictionary < Type , string > derivedTypesDictionary , out Document output )
727
+ SimplePropertyStorage parentPropertyStorage , out Document output )
725
728
{
726
729
output = null ;
727
730
@@ -734,7 +737,7 @@ private bool TryToMap(object value, [DynamicallyAccessedMembers(InternalConstant
734
737
return false ;
735
738
736
739
output = new Document ( ) ;
737
- SimplePropertyStorage propertyStorage = new SimplePropertyStorage ( valueType , derivedTypesDictionary ) ;
740
+ SimplePropertyStorage propertyStorage = new SimplePropertyStorage ( valueType , parentPropertyStorage ) ;
738
741
739
742
foreach ( object keyValue in idictionary . Keys )
740
743
{
@@ -755,7 +758,7 @@ private bool TryToMap(object value, [DynamicallyAccessedMembers(InternalConstant
755
758
}
756
759
757
760
private bool TryToList ( object value , [ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . Interfaces ) ] Type type , DynamoDBFlatConfig flatConfig ,
758
- Dictionary < Type , string > derivedTypesDictionary , out DynamoDBList output )
761
+ SimplePropertyStorage parentPropertyStoragey , out DynamoDBList output )
759
762
{
760
763
if ( ! Utils . ImplementsInterface ( type , typeof ( ICollection < > ) ) )
761
764
{
@@ -774,7 +777,7 @@ private bool TryToList(object value, [DynamicallyAccessedMembers(DynamicallyAcce
774
777
775
778
Type elementType = Utils . GetElementType ( type ) ;
776
779
777
- SimplePropertyStorage propertyStorage = new SimplePropertyStorage ( elementType , derivedTypesDictionary ) ;
780
+ SimplePropertyStorage propertyStorage = new SimplePropertyStorage ( elementType , parentPropertyStoragey ) ;
778
781
output = new DynamoDBList ( ) ;
779
782
foreach ( var item in enumerable )
780
783
{
0 commit comments