-
Notifications
You must be signed in to change notification settings - Fork 496
Expand file tree
/
Copy pathALBApiAttributeBuilder.cs
More file actions
48 lines (43 loc) · 1.74 KB
/
ALBApiAttributeBuilder.cs
File metadata and controls
48 lines (43 loc) · 1.74 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
using Amazon.Lambda.Annotations.ALB;
using Microsoft.CodeAnalysis;
using System;
namespace Amazon.Lambda.Annotations.SourceGenerator.Models.Attributes
{
/// <summary>
/// Builder for <see cref="ALBApiAttribute"/>.
/// </summary>
public class ALBApiAttributeBuilder
{
public static ALBApiAttribute Build(AttributeData att)
{
if (att.ConstructorArguments.Length != 3)
{
throw new NotSupportedException($"{TypeFullNames.ALBApiAttribute} must have constructor with 3 arguments.");
}
var listenerArn = att.ConstructorArguments[0].Value as string;
var pathPattern = att.ConstructorArguments[1].Value as string;
var priority = (int)att.ConstructorArguments[2].Value;
var data = new ALBApiAttribute(listenerArn, pathPattern, priority);
foreach (var pair in att.NamedArguments)
{
if (pair.Key == nameof(data.MultiValueHeaders) && pair.Value.Value is bool multiValueHeaders)
{
data.MultiValueHeaders = multiValueHeaders;
}
else if (pair.Key == nameof(data.HostHeader) && pair.Value.Value is string hostHeader)
{
data.HostHeader = hostHeader;
}
else if (pair.Key == nameof(data.HttpMethod) && pair.Value.Value is string httpMethod)
{
data.HttpMethod = httpMethod;
}
else if (pair.Key == nameof(data.ResourceName) && pair.Value.Value is string resourceName)
{
data.ResourceName = resourceName;
}
}
return data;
}
}
}