-
Notifications
You must be signed in to change notification settings - Fork 494
Expand file tree
/
Copy pathDynamoDBEventAttributeBuilder.cs
More file actions
52 lines (49 loc) · 2.01 KB
/
DynamoDBEventAttributeBuilder.cs
File metadata and controls
52 lines (49 loc) · 2.01 KB
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
using Amazon.Lambda.Annotations.DynamoDB;
using Microsoft.CodeAnalysis;
using System;
namespace Amazon.Lambda.Annotations.SourceGenerator.Models.Attributes
{
/// <summary>
/// Builder for <see cref="DynamoDBEventAttribute"/>.
/// </summary>
public class DynamoDBEventAttributeBuilder
{
public static DynamoDBEventAttribute Build(AttributeData att)
{
if (att.ConstructorArguments.Length != 1)
{
throw new NotSupportedException($"{TypeFullNames.DynamoDBEventAttribute} must have constructor with 1 argument.");
}
var stream = att.ConstructorArguments[0].Value as string;
var data = new DynamoDBEventAttribute(stream);
foreach (var pair in att.NamedArguments)
{
if (pair.Key == nameof(data.ResourceName) && pair.Value.Value is string resourceName)
{
data.ResourceName = resourceName;
}
if (pair.Key == nameof(data.BatchSize) && pair.Value.Value is uint batchSize)
{
data.BatchSize = batchSize;
}
else if (pair.Key == nameof(data.StartingPosition) && pair.Value.Value is string startingPosition)
{
data.StartingPosition = startingPosition;
}
else if (pair.Key == nameof(data.Enabled) && pair.Value.Value is bool enabled)
{
data.Enabled = enabled;
}
else if (pair.Key == nameof(data.MaximumBatchingWindowInSeconds) && pair.Value.Value is uint maximumBatchingWindowInSeconds)
{
data.MaximumBatchingWindowInSeconds = maximumBatchingWindowInSeconds;
}
else if (pair.Key == nameof(data.Filters) && pair.Value.Value is string filters)
{
data.Filters = filters;
}
}
return data;
}
}
}