20
20
using Amazon . DynamoDBv2 . DataModel ;
21
21
using Amazon . DynamoDBv2 . DocumentModel ;
22
22
using Amazon . Util . Internal ;
23
+ using System . Diagnostics . CodeAnalysis ;
24
+
23
25
24
26
#if NETSTANDARD
25
27
using Amazon . Runtime . Internal . Util ;
@@ -71,9 +73,6 @@ internal enum ConversionSchema
71
73
/// A collection of converters capable of converting between
72
74
/// .NET and DynamoDB objects.
73
75
/// </summary>
74
- #if NET8_0_OR_GREATER
75
- [ System . Diagnostics . CodeAnalysis . RequiresUnreferencedCode ( Amazon . DynamoDBv2 . Custom . Internal . InternalConstants . RequiresUnreferencedCodeMessage ) ]
76
- #endif
77
76
public class DynamoDBEntryConversion
78
77
{
79
78
#region Static members
@@ -252,7 +251,11 @@ public bool TryConvertToEntry(Type inputType, object value, out DynamoDBEntry en
252
251
/// <typeparam name="TOutput"></typeparam>
253
252
/// <param name="entry"></param>
254
253
/// <returns></returns>
254
+ #if NET8_0_OR_GREATER
255
+ public TOutput ConvertFromEntry < [ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . PublicMethods | DynamicallyAccessedMemberTypes . PublicConstructors ) ] TOutput > ( DynamoDBEntry entry )
256
+ #else
255
257
public TOutput ConvertFromEntry < TOutput > ( DynamoDBEntry entry )
258
+ #endif
256
259
{
257
260
TOutput output ;
258
261
if ( TryConvertFromEntry < TOutput > ( entry , out output ) )
@@ -269,7 +272,11 @@ public TOutput ConvertFromEntry<TOutput>(DynamoDBEntry entry)
269
272
/// <param name="entry"></param>
270
273
/// <returns></returns>
271
274
/// <exception cref="ArgumentNullException"></exception>
275
+ #if NET8_0_OR_GREATER
276
+ public object ConvertFromEntry ( [ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . PublicMethods | DynamicallyAccessedMemberTypes . PublicConstructors ) ] Type outputType , DynamoDBEntry entry )
277
+ #else
272
278
public object ConvertFromEntry ( Type outputType , DynamoDBEntry entry )
279
+ #endif
273
280
{
274
281
if ( outputType == null ) throw new ArgumentNullException ( "outputType" ) ;
275
282
if ( entry == null ) throw new ArgumentNullException ( "entry" ) ;
@@ -287,7 +294,11 @@ public object ConvertFromEntry(Type outputType, DynamoDBEntry entry)
287
294
/// <param name="entry"></param>
288
295
/// <param name="output"></param>
289
296
/// <returns>True if successfully converted, otherwise false.</returns>
297
+ #if NET8_0_OR_GREATER
298
+ public bool TryConvertFromEntry < [ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . PublicMethods | DynamicallyAccessedMemberTypes . PublicConstructors ) ] TOutput > ( DynamoDBEntry entry , out TOutput output )
299
+ #else
290
300
public bool TryConvertFromEntry < TOutput > ( DynamoDBEntry entry , out TOutput output )
301
+ #endif
291
302
{
292
303
output = default ( TOutput ) ;
293
304
@@ -313,7 +324,11 @@ public bool TryConvertFromEntry<TOutput>(DynamoDBEntry entry, out TOutput output
313
324
/// <param name="value"></param>
314
325
/// <returns></returns>
315
326
/// <exception cref="ArgumentNullException"></exception>
327
+ #if NET8_0_OR_GREATER
328
+ public bool TryConvertFromEntry ( [ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . PublicMethods | DynamicallyAccessedMemberTypes . PublicConstructors ) ] Type outputType , DynamoDBEntry entry , out object value )
329
+ #else
316
330
public bool TryConvertFromEntry ( Type outputType , DynamoDBEntry entry , out object value )
331
+ #endif
317
332
{
318
333
if ( outputType == null ) throw new ArgumentNullException ( "outputType" ) ;
319
334
if ( entry == null ) throw new ArgumentNullException ( "entry" ) ;
@@ -322,7 +337,7 @@ public bool TryConvertFromEntry(Type outputType, DynamoDBEntry entry, out object
322
337
return converter . TryFromEntry ( entry , outputType , out value ) ;
323
338
}
324
339
325
- #endregion
340
+ #endregion
326
341
327
342
#region Internal members
328
343
@@ -360,7 +375,12 @@ internal IEnumerable<DynamoDBEntry> ConvertToEntries<T>(IEnumerable<T> values)
360
375
//foreach (var value in values)
361
376
// yield return ConvertToEntry(value);
362
377
}
378
+
379
+ #if NET8_0_OR_GREATER
380
+ internal IEnumerable < object > ConvertFromEntries ( [ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . PublicMethods | DynamicallyAccessedMemberTypes . PublicConstructors ) ] Type elementType , IEnumerable < DynamoDBEntry > entries )
381
+ #else
363
382
internal IEnumerable < object > ConvertFromEntries ( Type elementType , IEnumerable < DynamoDBEntry > entries )
383
+ #endif
364
384
{
365
385
if ( entries == null ) throw new ArgumentNullException ( "entries" ) ;
366
386
@@ -377,7 +397,7 @@ internal PrimitiveList ItemsToPrimitiveList(IEnumerable items)
377
397
return pl ;
378
398
}
379
399
380
- #endregion
400
+ #endregion
381
401
382
402
#region Private members
383
403
@@ -539,7 +559,12 @@ public bool TryToEntry(object value, out DynamoDBEntry entry)
539
559
entry = null ;
540
560
return false ;
541
561
}
562
+
563
+ #if NET8_0_OR_GREATER
564
+ public object FromEntry ( DynamoDBEntry entry , [ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . PublicMethods | DynamicallyAccessedMemberTypes . PublicConstructors ) ] Type targetType )
565
+ #else
542
566
public object FromEntry ( DynamoDBEntry entry , Type targetType )
567
+ #endif
543
568
{
544
569
if ( entry == null ) throw new ArgumentNullException ( "entry" ) ;
545
570
if ( targetType == null ) throw new ArgumentNullException ( "targetType" ) ;
@@ -551,7 +576,12 @@ public object FromEntry(DynamoDBEntry entry, Type targetType)
551
576
throw new InvalidOperationException ( string . Format ( CultureInfo . InvariantCulture ,
552
577
"Unable to convert [{0}] of type {1} to {2}" , entry , entry . GetType ( ) . FullName , targetType . FullName ) ) ;
553
578
}
579
+
580
+ #if NET8_0_OR_GREATER
581
+ public bool TryFromEntry ( DynamoDBEntry entry , [ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . PublicMethods | DynamicallyAccessedMemberTypes . PublicConstructors ) ] Type targetType , out object value )
582
+ #else
554
583
public bool TryFromEntry ( DynamoDBEntry entry , Type targetType , out object value )
584
+ #endif
555
585
{
556
586
var p = entry as Primitive ;
557
587
@@ -627,17 +657,32 @@ public virtual bool TryFrom(DynamoDBBool b, Type targetType, out object result)
627
657
result = null ;
628
658
return false ;
629
659
}
660
+
661
+ #if NET8_0_OR_GREATER
662
+ public virtual bool TryFrom ( Primitive p , [ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . PublicMethods | DynamicallyAccessedMemberTypes . PublicConstructors ) ] Type targetType , out object result )
663
+ #else
630
664
public virtual bool TryFrom ( Primitive p , Type targetType , out object result )
665
+ #endif
631
666
{
632
667
result = null ;
633
668
return false ;
634
669
}
670
+
671
+ #if NET8_0_OR_GREATER
672
+ public virtual bool TryFrom ( PrimitiveList pl , [ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . PublicMethods | DynamicallyAccessedMemberTypes . PublicConstructors ) ] Type targetType , out object result )
673
+ #else
635
674
public virtual bool TryFrom ( PrimitiveList pl , Type targetType , out object result )
675
+ #endif
636
676
{
637
677
result = null ;
638
678
return false ;
639
679
}
680
+
681
+ #if NET8_0_OR_GREATER
682
+ public virtual bool TryFrom ( DynamoDBList l , [ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . PublicMethods | DynamicallyAccessedMemberTypes . PublicConstructors ) ] Type targetType , out object result )
683
+ #else
640
684
public virtual bool TryFrom ( DynamoDBList l , Type targetType , out object result )
685
+ #endif
641
686
{
642
687
result = null ;
643
688
return false ;
@@ -651,19 +696,6 @@ public virtual bool TryFrom(Document d, Type targetType, out object result)
651
696
652
697
internal abstract class Converter < T > : Converter
653
698
{
654
- public override IEnumerable < Type > GetTargetTypes ( )
655
- {
656
- var type = typeof ( T ) ;
657
- yield return type ;
658
-
659
- if ( type . IsValueType )
660
- {
661
- //yield return typeof(Nullable<T>);
662
- var nullableType = typeof ( Nullable < > ) . MakeGenericType ( type ) ;
663
- yield return nullableType ;
664
- }
665
- }
666
-
667
699
public override bool TryTo ( object value , out DynamoDBBool b )
668
700
{
669
701
return TryTo ( ( T ) value , out b ) ;
@@ -718,21 +750,36 @@ public override bool TryFrom(DynamoDBBool b, Type targetType, out object result)
718
750
result = t ;
719
751
return output ;
720
752
}
753
+
754
+ #if NET8_0_OR_GREATER
755
+ public override bool TryFrom ( Primitive p , [ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . PublicMethods | DynamicallyAccessedMemberTypes . PublicConstructors ) ] Type targetType , out object result )
756
+ #else
721
757
public override bool TryFrom ( Primitive p , Type targetType , out object result )
758
+ #endif
722
759
{
723
760
T t ;
724
761
var output = TryFrom ( p , targetType , out t ) ;
725
762
result = t ;
726
763
return output ;
727
764
}
765
+
766
+ #if NET8_0_OR_GREATER
767
+ public override bool TryFrom ( PrimitiveList pl , [ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . PublicMethods | DynamicallyAccessedMemberTypes . PublicConstructors ) ] Type targetType , out object result )
768
+ #else
728
769
public override bool TryFrom ( PrimitiveList pl , Type targetType , out object result )
770
+ #endif
729
771
{
730
772
T t ;
731
773
var output = TryFrom ( pl , targetType , out t ) ;
732
774
result = t ;
733
775
return output ;
734
776
}
777
+
778
+ #if NET8_0_OR_GREATER
779
+ public override bool TryFrom ( DynamoDBList l , [ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . PublicMethods | DynamicallyAccessedMemberTypes . PublicConstructors ) ] Type targetType , out object result )
780
+ #else
735
781
public override bool TryFrom ( DynamoDBList l , Type targetType , out object result )
782
+ #endif
736
783
{
737
784
T t ;
738
785
var output = TryFrom ( l , targetType , out t ) ;
@@ -752,7 +799,12 @@ protected virtual bool TryFrom(DynamoDBBool b, Type targetType, out T result)
752
799
result = default ( T ) ;
753
800
return false ;
754
801
}
802
+
803
+ #if NET8_0_OR_GREATER
804
+ protected virtual bool TryFrom ( Primitive p , [ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . PublicMethods | DynamicallyAccessedMemberTypes . PublicConstructors ) ] Type targetType , out T result )
805
+ #else
755
806
protected virtual bool TryFrom ( Primitive p , Type targetType , out T result )
807
+ #endif
756
808
{
757
809
result = default ( T ) ;
758
810
return false ;
0 commit comments