@@ -390,11 +390,10 @@ public MultiTableTransactWrite CreateMultiTableTransactWrite(params TransactWrit
390
390
391
391
#region Save/serialize
392
392
393
- private void SaveHelper < T > ( T value , DynamoDBOperationConfig operationConfig )
393
+ private void SaveHelper < T > ( T value , DynamoDBFlatConfig flatConfig )
394
394
{
395
395
if ( value == null ) return ;
396
396
397
- DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig ( operationConfig , this . Config ) ;
398
397
ItemStorage storage = ObjectToItemStorage ( value , false , flatConfig ) ;
399
398
if ( storage == null ) return ;
400
399
@@ -418,16 +417,15 @@ private void SaveHelper<T>(T value, DynamoDBOperationConfig operationConfig)
418
417
}
419
418
420
419
#if AWS_ASYNC_API
421
- private async Task SaveHelperAsync < T > ( T value , DynamoDBOperationConfig operationConfig , CancellationToken cancellationToken )
420
+ private async Task SaveHelperAsync < T > ( T value , DynamoDBFlatConfig flatConfig , CancellationToken cancellationToken )
422
421
{
423
- await SaveHelperAsync ( typeof ( T ) , value , operationConfig , cancellationToken ) . ConfigureAwait ( false ) ;
422
+ await SaveHelperAsync ( typeof ( T ) , value , flatConfig , cancellationToken ) . ConfigureAwait ( false ) ;
424
423
}
425
424
426
- private async Task SaveHelperAsync ( Type valueType , object value , DynamoDBOperationConfig operationConfig , CancellationToken cancellationToken )
425
+ private async Task SaveHelperAsync ( Type valueType , object value , DynamoDBFlatConfig flatConfig , CancellationToken cancellationToken )
427
426
{
428
427
if ( value == null ) return ;
429
428
430
- DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig ( operationConfig , this . Config ) ;
431
429
ItemStorage storage = ObjectToItemStorage ( value , valueType , false , flatConfig ) ;
432
430
if ( storage == null ) return ;
433
431
@@ -452,24 +450,14 @@ await table.UpdateHelperAsync(
452
450
}
453
451
#endif
454
452
455
- /// <summary>
456
- /// Serializes an object to a Document.
457
- /// </summary>
458
- /// <typeparam name="T">Type to serialize as.</typeparam>
459
- /// <param name="value">Object to serialize.</param>
460
- /// <returns>Document with attributes populated from object.</returns>
453
+ /// <inheritdoc/>
461
454
public Document ToDocument < T > ( T value )
462
455
{
463
- return ToDocument < T > ( value , null ) ;
456
+ return ToDocument < T > ( value , ( ToDocumentConfig ) null ) ;
464
457
}
465
458
466
- /// <summary>
467
- /// Serializes an object to a Document.
468
- /// </summary>
469
- /// <typeparam name="T">Type to serialize as.</typeparam>
470
- /// <param name="value">Object to serialize.</param>
471
- /// <param name="operationConfig">Config object which can be used to override the table used.</param>
472
- /// <returns>Document with attributes populated from object.</returns>
459
+ /// <inheritdoc/>
460
+ [ Obsolete ( "Use the ToDocument overload that takes ToDocumentConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to ToDocument." ) ]
473
461
public Document ToDocument < T > ( T value , DynamoDBOperationConfig operationConfig )
474
462
{
475
463
if ( value == null ) return null ;
@@ -481,40 +469,48 @@ public Document ToDocument<T>(T value, DynamoDBOperationConfig operationConfig)
481
469
return storage . Document ;
482
470
}
483
471
472
+ /// <inheritdoc/>
473
+ public Document ToDocument < T > ( T value , ToDocumentConfig toDocumentConfig )
474
+ {
475
+ if ( value == null ) return null ;
476
+
477
+ DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig ( toDocumentConfig ? . ToDynamoDBOperationConfig ( ) , Config ) ;
478
+ ItemStorage storage = ObjectToItemStorage < T > ( value , false , flatConfig ) ;
479
+ if ( storage == null ) return null ;
480
+
481
+ return storage . Document ;
482
+ }
483
+
484
484
#endregion
485
485
486
486
#region Load/deserialize
487
487
488
- private T LoadHelper < T > ( object hashKey , object rangeKey , DynamoDBOperationConfig operationConfig )
488
+ private T LoadHelper < T > ( object hashKey , object rangeKey , DynamoDBFlatConfig flatConfig )
489
489
{
490
- DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig ( operationConfig , this . Config ) ;
491
490
ItemStorageConfig storageConfig = StorageConfigCache . GetConfig < T > ( flatConfig ) ;
492
491
Key key = MakeKey ( hashKey , rangeKey , storageConfig , flatConfig ) ;
493
492
return LoadHelper < T > ( key , flatConfig , storageConfig ) ;
494
493
}
495
494
496
495
#if AWS_ASYNC_API
497
- private Task < T > LoadHelperAsync < T > ( object hashKey , object rangeKey , DynamoDBOperationConfig operationConfig , CancellationToken cancellationToken )
496
+ private Task < T > LoadHelperAsync < T > ( object hashKey , object rangeKey , DynamoDBFlatConfig flatConfig , CancellationToken cancellationToken )
498
497
{
499
- DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig ( operationConfig , this . Config ) ;
500
498
ItemStorageConfig storageConfig = StorageConfigCache . GetConfig < T > ( flatConfig ) ;
501
499
Key key = MakeKey ( hashKey , rangeKey , storageConfig , flatConfig ) ;
502
500
return LoadHelperAsync < T > ( key , flatConfig , storageConfig , cancellationToken ) ;
503
501
}
504
502
#endif
505
503
506
- private T LoadHelper < T > ( T keyObject , DynamoDBOperationConfig operationConfig )
504
+ private T LoadHelper < T > ( T keyObject , DynamoDBFlatConfig flatConfig )
507
505
{
508
- DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig ( operationConfig , this . Config ) ;
509
506
ItemStorageConfig storageConfig = StorageConfigCache . GetConfig < T > ( flatConfig ) ;
510
507
Key key = MakeKey < T > ( keyObject , storageConfig , flatConfig ) ;
511
508
return LoadHelper < T > ( key , flatConfig , storageConfig ) ;
512
509
}
513
510
514
511
#if AWS_ASYNC_API
515
- private Task < T > LoadHelperAsync < T > ( T keyObject , DynamoDBOperationConfig operationConfig , CancellationToken cancellationToken )
512
+ private Task < T > LoadHelperAsync < T > ( T keyObject , DynamoDBFlatConfig flatConfig , CancellationToken cancellationToken )
516
513
{
517
- DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig ( operationConfig , this . Config ) ;
518
514
ItemStorageConfig storageConfig = StorageConfigCache . GetConfig < T > ( flatConfig ) ;
519
515
Key key = MakeKey < T > ( keyObject , storageConfig , flatConfig ) ;
520
516
return LoadHelperAsync < T > ( key , flatConfig , storageConfig , cancellationToken ) ;
@@ -555,34 +551,27 @@ private async Task<T> LoadHelperAsync<T>(Key key, DynamoDBFlatConfig flatConfig,
555
551
}
556
552
#endif
557
553
558
- /// <summary>
559
- /// Deserializes a document to an instance of type T.
560
- /// </summary>
561
- /// <typeparam name="T">Type to populate.</typeparam>
562
- /// <param name="document">Document with properties to use.</param>
563
- /// <returns>
564
- /// Object of type T, populated with properties from the document.
565
- /// </returns>
554
+ /// <inheritdoc/>
566
555
public T FromDocument < T > ( Document document )
567
556
{
568
- return FromDocument < T > ( document , null ) ;
557
+ return FromDocument < T > ( document , ( FromDocumentConfig ) null ) ;
569
558
}
570
559
571
- /// <summary>
572
- /// Deserializes a document to an instance of type T.
573
- /// </summary>
574
- /// <typeparam name="T">Type to populate.</typeparam>
575
- /// <param name="document">Document with properties to use.</param>
576
- /// <param name="operationConfig">Config object which can be used to override the table used.</param>
577
- /// <returns>
578
- /// Object of type T, populated with properties from the document.
579
- /// </returns>
560
+ /// <inheritdoc/>
561
+ [ Obsolete ( "Use the FromDocument overload that takes FromDocumentConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to FromDocument." ) ]
580
562
public T FromDocument < T > ( Document document , DynamoDBOperationConfig operationConfig )
581
563
{
582
564
DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig ( operationConfig , Config ) ;
583
565
return FromDocumentHelper < T > ( document , flatConfig ) ;
584
566
}
585
567
568
+ /// <inheritdoc/>
569
+ public T FromDocument < T > ( Document document , FromDocumentConfig fromDocumentConfig )
570
+ {
571
+ DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig ( fromDocumentConfig ? . ToDynamoDBOperationConfig ( ) , Config ) ;
572
+ return FromDocumentHelper < T > ( document , flatConfig ) ;
573
+ }
574
+
586
575
internal T FromDocumentHelper < T > ( Document document , DynamoDBFlatConfig flatConfig )
587
576
{
588
577
ItemStorageConfig storageConfig = StorageConfigCache . GetConfig < T > ( flatConfig ) ;
@@ -592,28 +581,14 @@ internal T FromDocumentHelper<T>(Document document, DynamoDBFlatConfig flatConfi
592
581
return instance ;
593
582
}
594
583
595
- /// <summary>
596
- /// Deserializes a collections of documents to a collection of instances of type T.
597
- /// </summary>
598
- /// <typeparam name="T">Type to populate.</typeparam>
599
- /// <param name="documents">Documents to deserialize.</param>
600
- /// <returns>
601
- /// Collection of items of type T, each populated with properties from a corresponding document.
602
- /// </returns>
584
+ /// <inheritdoc/>
603
585
public IEnumerable < T > FromDocuments < T > ( IEnumerable < Document > documents )
604
586
{
605
- return FromDocuments < T > ( documents , null ) ;
587
+ return FromDocuments < T > ( documents , ( FromDocumentConfig ) null ) ;
606
588
}
607
589
608
- /// <summary>
609
- /// Deserializes a collections of documents to a collection of instances of type T.
610
- /// </summary>
611
- /// <typeparam name="T">Type to populate.</typeparam>
612
- /// <param name="documents">Documents to deserialize.</param>
613
- /// <param name="operationConfig">Config object which can be used to override the table used.</param>
614
- /// <returns>
615
- /// Collection of items of type T, each populated with properties from a corresponding document.
616
- /// </returns>
590
+ /// <inheritdoc/>
591
+ [ Obsolete ( "Use the FromDocuments overload that takes FromDocumentConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to FromDocuments." ) ]
617
592
public IEnumerable < T > FromDocuments < T > ( IEnumerable < Document > documents , DynamoDBOperationConfig operationConfig )
618
593
{
619
594
foreach ( var document in documents )
@@ -623,6 +598,16 @@ public IEnumerable<T> FromDocuments<T>(IEnumerable<Document> documents, DynamoDB
623
598
}
624
599
}
625
600
601
+ /// <inheritdoc/>
602
+ public IEnumerable < T > FromDocuments < T > ( IEnumerable < Document > documents , FromDocumentConfig fromDocumentConfig )
603
+ {
604
+ foreach ( var document in documents )
605
+ {
606
+ T item = FromDocument < T > ( document , fromDocumentConfig ) ;
607
+ yield return item ;
608
+ }
609
+ }
610
+
626
611
internal IEnumerable < T > FromDocumentsHelper < T > ( IEnumerable < Document > documents , DynamoDBFlatConfig flatConfig )
627
612
{
628
613
foreach ( var document in documents )
@@ -636,33 +621,30 @@ internal IEnumerable<T> FromDocumentsHelper<T>(IEnumerable<Document> documents,
636
621
637
622
#region Delete
638
623
639
- private void DeleteHelper < T > ( object hashKey , object rangeKey , DynamoDBOperationConfig operationConfig )
624
+ private void DeleteHelper < T > ( object hashKey , object rangeKey , DynamoDBFlatConfig flatConfig )
640
625
{
641
- DynamoDBFlatConfig config = new DynamoDBFlatConfig ( operationConfig , this . Config ) ;
642
- ItemStorageConfig storageConfig = StorageConfigCache . GetConfig < T > ( config ) ;
643
- Key key = MakeKey ( hashKey , rangeKey , storageConfig , config ) ;
626
+ ItemStorageConfig storageConfig = StorageConfigCache . GetConfig < T > ( flatConfig ) ;
627
+ Key key = MakeKey ( hashKey , rangeKey , storageConfig , flatConfig ) ;
644
628
645
- Table table = GetTargetTable ( storageConfig , config ) ;
629
+ Table table = GetTargetTable ( storageConfig , flatConfig ) ;
646
630
table . DeleteHelper ( key , null ) ;
647
631
}
648
632
649
633
#if AWS_ASYNC_API
650
- private Task DeleteHelperAsync < T > ( object hashKey , object rangeKey , DynamoDBOperationConfig operationConfig , CancellationToken cancellationToken )
634
+ private Task DeleteHelperAsync < T > ( object hashKey , object rangeKey , DynamoDBFlatConfig flatConfig , CancellationToken cancellationToken )
651
635
{
652
- DynamoDBFlatConfig config = new DynamoDBFlatConfig ( operationConfig , this . Config ) ;
653
- ItemStorageConfig storageConfig = StorageConfigCache . GetConfig < T > ( config ) ;
654
- Key key = MakeKey ( hashKey , rangeKey , storageConfig , config ) ;
636
+ ItemStorageConfig storageConfig = StorageConfigCache . GetConfig < T > ( flatConfig ) ;
637
+ Key key = MakeKey ( hashKey , rangeKey , storageConfig , flatConfig ) ;
655
638
656
- Table table = GetTargetTable ( storageConfig , config ) ;
639
+ Table table = GetTargetTable ( storageConfig , flatConfig ) ;
657
640
return table . DeleteHelperAsync ( key , null , cancellationToken ) ;
658
641
}
659
642
#endif
660
643
661
- private void DeleteHelper < T > ( T value , DynamoDBOperationConfig operationConfig )
644
+ private void DeleteHelper < T > ( T value , DynamoDBFlatConfig flatConfig )
662
645
{
663
646
if ( value == null ) throw new ArgumentNullException ( "value" ) ;
664
647
665
- DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig ( operationConfig , this . Config ) ;
666
648
flatConfig . IgnoreNullValues = true ;
667
649
ItemStorage storage = ObjectToItemStorage < T > ( value , true , flatConfig ) ;
668
650
if ( storage == null ) return ;
@@ -685,11 +667,10 @@ private void DeleteHelper<T>(T value, DynamoDBOperationConfig operationConfig)
685
667
686
668
private static readonly Task CompletedTask = Task . FromResult < object > ( null ) ;
687
669
688
- private Task DeleteHelperAsync < T > ( T value , DynamoDBOperationConfig operationConfig , CancellationToken cancellationToken )
670
+ private Task DeleteHelperAsync < T > ( T value , DynamoDBFlatConfig flatConfig , CancellationToken cancellationToken )
689
671
{
690
672
if ( value == null ) throw new ArgumentNullException ( "value" ) ;
691
673
692
- DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig ( operationConfig , this . Config ) ;
693
674
flatConfig . IgnoreNullValues = true ;
694
675
ItemStorage storage = ObjectToItemStorage ( value , true , flatConfig ) ;
695
676
if ( storage == null ) return CompletedTask ;
0 commit comments