@@ -475,11 +475,10 @@ public MultiTableTransactWrite CreateMultiTableTransactWrite(params TransactWrit
475
475
476
476
#region Save/serialize
477
477
478
- private void SaveHelper < T > ( T value , DynamoDBOperationConfig operationConfig )
478
+ private void SaveHelper < T > ( T value , DynamoDBFlatConfig flatConfig )
479
479
{
480
480
if ( value == null ) return ;
481
481
482
- DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig ( operationConfig , this . Config ) ;
483
482
ItemStorage storage = ObjectToItemStorage ( value , false , flatConfig ) ;
484
483
if ( storage == null ) return ;
485
484
@@ -503,16 +502,15 @@ private void SaveHelper<T>(T value, DynamoDBOperationConfig operationConfig)
503
502
}
504
503
505
504
#if AWS_ASYNC_API
506
- private async Task SaveHelperAsync < T > ( T value , DynamoDBOperationConfig operationConfig , CancellationToken cancellationToken )
505
+ private async Task SaveHelperAsync < T > ( T value , DynamoDBFlatConfig flatConfig , CancellationToken cancellationToken )
507
506
{
508
- await SaveHelperAsync ( typeof ( T ) , value , operationConfig , cancellationToken ) . ConfigureAwait ( false ) ;
507
+ await SaveHelperAsync ( typeof ( T ) , value , flatConfig , cancellationToken ) . ConfigureAwait ( false ) ;
509
508
}
510
509
511
- private async Task SaveHelperAsync ( Type valueType , object value , DynamoDBOperationConfig operationConfig , CancellationToken cancellationToken )
510
+ private async Task SaveHelperAsync ( Type valueType , object value , DynamoDBFlatConfig flatConfig , CancellationToken cancellationToken )
512
511
{
513
512
if ( value == null ) return ;
514
513
515
- DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig ( operationConfig , this . Config ) ;
516
514
ItemStorage storage = ObjectToItemStorage ( value , valueType , false , flatConfig ) ;
517
515
if ( storage == null ) return ;
518
516
@@ -537,24 +535,14 @@ await table.UpdateHelperAsync(
537
535
}
538
536
#endif
539
537
540
- /// <summary>
541
- /// Serializes an object to a Document.
542
- /// </summary>
543
- /// <typeparam name="T">Type to serialize as.</typeparam>
544
- /// <param name="value">Object to serialize.</param>
545
- /// <returns>Document with attributes populated from object.</returns>
538
+ /// <inheritdoc/>
546
539
public Document ToDocument < T > ( T value )
547
540
{
548
- return ToDocument < T > ( value , null ) ;
541
+ return ToDocument < T > ( value , ( ToDocumentConfig ) null ) ;
549
542
}
550
543
551
- /// <summary>
552
- /// Serializes an object to a Document.
553
- /// </summary>
554
- /// <typeparam name="T">Type to serialize as.</typeparam>
555
- /// <param name="value">Object to serialize.</param>
556
- /// <param name="operationConfig">Config object which can be used to override the table used.</param>
557
- /// <returns>Document with attributes populated from object.</returns>
544
+ /// <inheritdoc/>
545
+ [ Obsolete ( "Use the ToDocument overload that takes ToDocumentConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to ToDocument." ) ]
558
546
public Document ToDocument < T > ( T value , DynamoDBOperationConfig operationConfig )
559
547
{
560
548
if ( value == null ) return null ;
@@ -566,40 +554,48 @@ public Document ToDocument<T>(T value, DynamoDBOperationConfig operationConfig)
566
554
return storage . Document ;
567
555
}
568
556
557
+ /// <inheritdoc/>
558
+ public Document ToDocument < T > ( T value , ToDocumentConfig toDocumentConfig )
559
+ {
560
+ if ( value == null ) return null ;
561
+
562
+ DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig ( toDocumentConfig ? . ToDynamoDBOperationConfig ( ) , Config ) ;
563
+ ItemStorage storage = ObjectToItemStorage < T > ( value , false , flatConfig ) ;
564
+ if ( storage == null ) return null ;
565
+
566
+ return storage . Document ;
567
+ }
568
+
569
569
#endregion
570
570
571
571
#region Load/deserialize
572
572
573
- private T LoadHelper < T > ( object hashKey , object rangeKey , DynamoDBOperationConfig operationConfig )
573
+ private T LoadHelper < T > ( object hashKey , object rangeKey , DynamoDBFlatConfig flatConfig )
574
574
{
575
- DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig ( operationConfig , this . Config ) ;
576
575
ItemStorageConfig storageConfig = StorageConfigCache . GetConfig < T > ( flatConfig ) ;
577
576
Key key = MakeKey ( hashKey , rangeKey , storageConfig , flatConfig ) ;
578
577
return LoadHelper < T > ( key , flatConfig , storageConfig ) ;
579
578
}
580
579
581
580
#if AWS_ASYNC_API
582
- private Task < T > LoadHelperAsync < T > ( object hashKey , object rangeKey , DynamoDBOperationConfig operationConfig , CancellationToken cancellationToken )
581
+ private Task < T > LoadHelperAsync < T > ( object hashKey , object rangeKey , DynamoDBFlatConfig flatConfig , CancellationToken cancellationToken )
583
582
{
584
- DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig ( operationConfig , this . Config ) ;
585
583
ItemStorageConfig storageConfig = StorageConfigCache . GetConfig < T > ( flatConfig ) ;
586
584
Key key = MakeKey ( hashKey , rangeKey , storageConfig , flatConfig ) ;
587
585
return LoadHelperAsync < T > ( key , flatConfig , storageConfig , cancellationToken ) ;
588
586
}
589
587
#endif
590
588
591
- private T LoadHelper < T > ( T keyObject , DynamoDBOperationConfig operationConfig )
589
+ private T LoadHelper < T > ( T keyObject , DynamoDBFlatConfig flatConfig )
592
590
{
593
- DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig ( operationConfig , this . Config ) ;
594
591
ItemStorageConfig storageConfig = StorageConfigCache . GetConfig < T > ( flatConfig ) ;
595
592
Key key = MakeKey < T > ( keyObject , storageConfig , flatConfig ) ;
596
593
return LoadHelper < T > ( key , flatConfig , storageConfig ) ;
597
594
}
598
595
599
596
#if AWS_ASYNC_API
600
- private Task < T > LoadHelperAsync < T > ( T keyObject , DynamoDBOperationConfig operationConfig , CancellationToken cancellationToken )
597
+ private Task < T > LoadHelperAsync < T > ( T keyObject , DynamoDBFlatConfig flatConfig , CancellationToken cancellationToken )
601
598
{
602
- DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig ( operationConfig , this . Config ) ;
603
599
ItemStorageConfig storageConfig = StorageConfigCache . GetConfig < T > ( flatConfig ) ;
604
600
Key key = MakeKey < T > ( keyObject , storageConfig , flatConfig ) ;
605
601
return LoadHelperAsync < T > ( key , flatConfig , storageConfig , cancellationToken ) ;
@@ -640,34 +636,27 @@ private async Task<T> LoadHelperAsync<T>(Key key, DynamoDBFlatConfig flatConfig,
640
636
}
641
637
#endif
642
638
643
- /// <summary>
644
- /// Deserializes a document to an instance of type T.
645
- /// </summary>
646
- /// <typeparam name="T">Type to populate.</typeparam>
647
- /// <param name="document">Document with properties to use.</param>
648
- /// <returns>
649
- /// Object of type T, populated with properties from the document.
650
- /// </returns>
639
+ /// <inheritdoc/>
651
640
public T FromDocument < T > ( Document document )
652
641
{
653
- return FromDocument < T > ( document , null ) ;
642
+ return FromDocument < T > ( document , ( FromDocumentConfig ) null ) ;
654
643
}
655
644
656
- /// <summary>
657
- /// Deserializes a document to an instance of type T.
658
- /// </summary>
659
- /// <typeparam name="T">Type to populate.</typeparam>
660
- /// <param name="document">Document with properties to use.</param>
661
- /// <param name="operationConfig">Config object which can be used to override the table used.</param>
662
- /// <returns>
663
- /// Object of type T, populated with properties from the document.
664
- /// </returns>
645
+ /// <inheritdoc/>
646
+ [ Obsolete ( "Use the FromDocument overload that takes FromDocumentConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to FromDocument." ) ]
665
647
public T FromDocument < T > ( Document document , DynamoDBOperationConfig operationConfig )
666
648
{
667
649
DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig ( operationConfig , Config ) ;
668
650
return FromDocumentHelper < T > ( document , flatConfig ) ;
669
651
}
670
652
653
+ /// <inheritdoc/>
654
+ public T FromDocument < T > ( Document document , FromDocumentConfig fromDocumentConfig )
655
+ {
656
+ DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig ( fromDocumentConfig ? . ToDynamoDBOperationConfig ( ) , Config ) ;
657
+ return FromDocumentHelper < T > ( document , flatConfig ) ;
658
+ }
659
+
671
660
internal T FromDocumentHelper < T > ( Document document , DynamoDBFlatConfig flatConfig )
672
661
{
673
662
ItemStorageConfig storageConfig = StorageConfigCache . GetConfig < T > ( flatConfig ) ;
@@ -677,28 +666,14 @@ internal T FromDocumentHelper<T>(Document document, DynamoDBFlatConfig flatConfi
677
666
return instance ;
678
667
}
679
668
680
- /// <summary>
681
- /// Deserializes a collections of documents to a collection of instances of type T.
682
- /// </summary>
683
- /// <typeparam name="T">Type to populate.</typeparam>
684
- /// <param name="documents">Documents to deserialize.</param>
685
- /// <returns>
686
- /// Collection of items of type T, each populated with properties from a corresponding document.
687
- /// </returns>
669
+ /// <inheritdoc/>
688
670
public IEnumerable < T > FromDocuments < T > ( IEnumerable < Document > documents )
689
671
{
690
- return FromDocuments < T > ( documents , null ) ;
672
+ return FromDocuments < T > ( documents , ( FromDocumentConfig ) null ) ;
691
673
}
692
674
693
- /// <summary>
694
- /// Deserializes a collections of documents to a collection of instances of type T.
695
- /// </summary>
696
- /// <typeparam name="T">Type to populate.</typeparam>
697
- /// <param name="documents">Documents to deserialize.</param>
698
- /// <param name="operationConfig">Config object which can be used to override the table used.</param>
699
- /// <returns>
700
- /// Collection of items of type T, each populated with properties from a corresponding document.
701
- /// </returns>
675
+ /// <inheritdoc/>
676
+ [ Obsolete ( "Use the FromDocuments overload that takes FromDocumentConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to FromDocuments." ) ]
702
677
public IEnumerable < T > FromDocuments < T > ( IEnumerable < Document > documents , DynamoDBOperationConfig operationConfig )
703
678
{
704
679
foreach ( var document in documents )
@@ -708,6 +683,16 @@ public IEnumerable<T> FromDocuments<T>(IEnumerable<Document> documents, DynamoDB
708
683
}
709
684
}
710
685
686
+ /// <inheritdoc/>
687
+ public IEnumerable < T > FromDocuments < T > ( IEnumerable < Document > documents , FromDocumentConfig fromDocumentConfig )
688
+ {
689
+ foreach ( var document in documents )
690
+ {
691
+ T item = FromDocument < T > ( document , fromDocumentConfig ) ;
692
+ yield return item ;
693
+ }
694
+ }
695
+
711
696
internal IEnumerable < T > FromDocumentsHelper < T > ( IEnumerable < Document > documents , DynamoDBFlatConfig flatConfig )
712
697
{
713
698
foreach ( var document in documents )
@@ -721,33 +706,30 @@ internal IEnumerable<T> FromDocumentsHelper<T>(IEnumerable<Document> documents,
721
706
722
707
#region Delete
723
708
724
- private void DeleteHelper < T > ( object hashKey , object rangeKey , DynamoDBOperationConfig operationConfig )
709
+ private void DeleteHelper < T > ( object hashKey , object rangeKey , DynamoDBFlatConfig flatConfig )
725
710
{
726
- DynamoDBFlatConfig config = new DynamoDBFlatConfig ( operationConfig , this . Config ) ;
727
- ItemStorageConfig storageConfig = StorageConfigCache . GetConfig < T > ( config ) ;
728
- Key key = MakeKey ( hashKey , rangeKey , storageConfig , config ) ;
711
+ ItemStorageConfig storageConfig = StorageConfigCache . GetConfig < T > ( flatConfig ) ;
712
+ Key key = MakeKey ( hashKey , rangeKey , storageConfig , flatConfig ) ;
729
713
730
- Table table = GetTargetTable ( storageConfig , config ) ;
714
+ Table table = GetTargetTable ( storageConfig , flatConfig ) ;
731
715
table . DeleteHelper ( key , null ) ;
732
716
}
733
717
734
718
#if AWS_ASYNC_API
735
- private Task DeleteHelperAsync < T > ( object hashKey , object rangeKey , DynamoDBOperationConfig operationConfig , CancellationToken cancellationToken )
719
+ private Task DeleteHelperAsync < T > ( object hashKey , object rangeKey , DynamoDBFlatConfig flatConfig , CancellationToken cancellationToken )
736
720
{
737
- DynamoDBFlatConfig config = new DynamoDBFlatConfig ( operationConfig , this . Config ) ;
738
- ItemStorageConfig storageConfig = StorageConfigCache . GetConfig < T > ( config ) ;
739
- Key key = MakeKey ( hashKey , rangeKey , storageConfig , config ) ;
721
+ ItemStorageConfig storageConfig = StorageConfigCache . GetConfig < T > ( flatConfig ) ;
722
+ Key key = MakeKey ( hashKey , rangeKey , storageConfig , flatConfig ) ;
740
723
741
- Table table = GetTargetTable ( storageConfig , config ) ;
724
+ Table table = GetTargetTable ( storageConfig , flatConfig ) ;
742
725
return table . DeleteHelperAsync ( key , null , cancellationToken ) ;
743
726
}
744
727
#endif
745
728
746
- private void DeleteHelper < T > ( T value , DynamoDBOperationConfig operationConfig )
729
+ private void DeleteHelper < T > ( T value , DynamoDBFlatConfig flatConfig )
747
730
{
748
731
if ( value == null ) throw new ArgumentNullException ( "value" ) ;
749
732
750
- DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig ( operationConfig , this . Config ) ;
751
733
flatConfig . IgnoreNullValues = true ;
752
734
ItemStorage storage = ObjectToItemStorage < T > ( value , true , flatConfig ) ;
753
735
if ( storage == null ) return ;
@@ -770,11 +752,10 @@ private void DeleteHelper<T>(T value, DynamoDBOperationConfig operationConfig)
770
752
771
753
private static readonly Task CompletedTask = Task . FromResult < object > ( null ) ;
772
754
773
- private Task DeleteHelperAsync < T > ( T value , DynamoDBOperationConfig operationConfig , CancellationToken cancellationToken )
755
+ private Task DeleteHelperAsync < T > ( T value , DynamoDBFlatConfig flatConfig , CancellationToken cancellationToken )
774
756
{
775
757
if ( value == null ) throw new ArgumentNullException ( "value" ) ;
776
758
777
- DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig ( operationConfig , this . Config ) ;
778
759
flatConfig . IgnoreNullValues = true ;
779
760
ItemStorage storage = ObjectToItemStorage ( value , true , flatConfig ) ;
780
761
if ( storage == null ) return CompletedTask ;
0 commit comments