|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using Amazon.DynamoDBv2.Model; |
| 4 | +using DynamoMapper.Runtime; |
| 5 | + |
| 6 | +namespace DynamoMapper.Inheritance; |
| 7 | + |
| 8 | +[DynamoMapper] |
| 9 | +internal static partial class OrderMapper_Default |
| 10 | +{ |
| 11 | + internal static partial Dictionary<string, AttributeValue> ToItem(Order source); |
| 12 | + |
| 13 | + internal static partial Order FromItem(Dictionary<string, AttributeValue> item); |
| 14 | +} |
| 15 | + |
| 16 | +[DynamoMapper(IncludeBaseClassProperties = true)] |
| 17 | +internal static partial class OrderMapper_WithBaseProps |
| 18 | +{ |
| 19 | + internal static partial Dictionary<string, AttributeValue> ToItem(Order source); |
| 20 | + |
| 21 | + internal static partial Order FromItem(Dictionary<string, AttributeValue> item); |
| 22 | +} |
| 23 | + |
| 24 | +internal class BaseEntity |
| 25 | +{ |
| 26 | + internal string Id { get; set; } = string.Empty; |
| 27 | +} |
| 28 | + |
| 29 | +internal class Order : BaseEntity |
| 30 | +{ |
| 31 | + internal string Name { get; set; } = string.Empty; |
| 32 | +} |
| 33 | + |
| 34 | +internal static class Program |
| 35 | +{ |
| 36 | + private static void Main() |
| 37 | + { |
| 38 | + var order = new Order { Id = "order-123", Name = "Sample Order" }; |
| 39 | + |
| 40 | + var itemDefault = OrderMapper_Default.ToItem(order); |
| 41 | + var itemWithBase = OrderMapper_WithBaseProps.ToItem(order); |
| 42 | + |
| 43 | + Console.WriteLine("Default mapper keys: " + string.Join(", ", itemDefault.Keys)); |
| 44 | + Console.WriteLine("With base props keys: " + string.Join(", ", itemWithBase.Keys)); |
| 45 | + |
| 46 | + var roundTripDefault = OrderMapper_Default.FromItem(itemWithBase); |
| 47 | + var roundTripWithBase = OrderMapper_WithBaseProps.FromItem(itemWithBase); |
| 48 | + |
| 49 | + Console.WriteLine("Default mapper Id: '" + roundTripDefault.Id + "'"); |
| 50 | + Console.WriteLine("With base props Id: '" + roundTripWithBase.Id + "'"); |
| 51 | + } |
| 52 | +} |
0 commit comments