-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDynamoDBMarshallerAttribute.cs
68 lines (64 loc) · 2.78 KB
/
DynamoDBMarshallerAttribute.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
namespace DynamoDBGenerator.Attributes;
/// <summary>
/// Attribute used to source generate an implementation of <see cref="IDynamoDBMarshaller{TEntity,TArg,TEntityAttributeNameTracker,TArgumentAttributeValueTracker}" />.
/// </summary>
/// <example>
/// The example below demonstrates a console app where this attribute is used:
/// <code>
/// public class Program
/// {
/// public static void Main(string[] args)
/// {
/// var orderEntity = new OrderEntity
/// {
/// Id = "1",
/// Cost = 2.3
/// };
/// var attributeValues = OrderEntity.MyCustomPropertyName.Marshall(orderEntity);
/// foreach(var keyValue in attributeValues)
/// {
/// Console.WriteLine(attributeValues);
/// }
/// }
/// }
/// [DynamoDBMarshaller(EntityType = typeof(OrderEntity), AccessName = "MyCustomPropertyName"))]
/// public class OrderEntity
/// {
/// [DynamoDBHashKey]
/// public string Id { get; set; }
/// public decimal Cost { get; set; }
/// }
/// </code>
/// </example>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = true)]
public class DynamoDBMarshallerAttribute : Attribute
{
/// <summary>
/// Gets or sets the type that will be used for marshalling and unmarshalling.
/// </summary>
/// <remarks>
/// The default value will be the type where the attribute was applied to.
/// </remarks>
public Type? EntityType { get; set; }
/// <summary>
/// Gets or sets the name for how the marshaller is accessed.
/// </summary>
/// <remarks>
/// <para>
/// The default value will be dependant on the <see cref="EntityType"/> by having the naming format of `{Type.Name}Marshaller` but without the reflection.
/// </para>
/// <para>
/// By default it the marshaller can be accessed as a property, but can be transformed into a method if you add constructor dependencies to <see cref="DynamoDbMarshallerOptionsAttribute.Converters" />
/// </para>
/// </remarks>
public string? AccessName { get; set; }
/// <summary>
/// Gets or sets the type that <see cref="IDynamoDBMarshaller{TEntity,TArg,TEntityAttributeNameTracker,TArgumentAttributeValueTracker}"/>
/// will use as its argument type-parameter.
/// </summary>
/// <remarks>
/// The default value will be <see cref="EntityType"/>, this is will make the the generated code be implemented in a PUT oriented manner.
/// </remarks>
public Type? ArgumentType { get; set; }
}