-
Notifications
You must be signed in to change notification settings - Fork 494
Expand file tree
/
Copy pathSNSEventAttributeBuilder.cs
More file actions
40 lines (37 loc) · 1.35 KB
/
SNSEventAttributeBuilder.cs
File metadata and controls
40 lines (37 loc) · 1.35 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
using Amazon.Lambda.Annotations.SNS;
using Microsoft.CodeAnalysis;
using System;
namespace Amazon.Lambda.Annotations.SourceGenerator.Models.Attributes
{
/// <summary>
/// Builder for <see cref="SNSEventAttribute"/>.
/// </summary>
public class SNSEventAttributeBuilder
{
public static SNSEventAttribute Build(AttributeData att)
{
if (att.ConstructorArguments.Length != 1)
{
throw new NotSupportedException($"{TypeFullNames.SNSEventAttribute} must have constructor with 1 argument.");
}
var topic = att.ConstructorArguments[0].Value as string;
var data = new SNSEventAttribute(topic);
foreach (var pair in att.NamedArguments)
{
if (pair.Key == nameof(data.ResourceName) && pair.Value.Value is string resourceName)
{
data.ResourceName = resourceName;
}
else if (pair.Key == nameof(data.FilterPolicy) && pair.Value.Value is string filterPolicy)
{
data.FilterPolicy = filterPolicy;
}
else if (pair.Key == nameof(data.Enabled) && pair.Value.Value is bool enabled)
{
data.Enabled = enabled;
}
}
return data;
}
}
}