-
Notifications
You must be signed in to change notification settings - Fork 494
Expand file tree
/
Copy pathScheduleEventAttributeBuilder.cs
More file actions
44 lines (41 loc) · 1.55 KB
/
ScheduleEventAttributeBuilder.cs
File metadata and controls
44 lines (41 loc) · 1.55 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
using Amazon.Lambda.Annotations.Schedule;
using Microsoft.CodeAnalysis;
using System;
namespace Amazon.Lambda.Annotations.SourceGenerator.Models.Attributes
{
/// <summary>
/// Builder for <see cref="ScheduleEventAttribute"/>.
/// </summary>
public class ScheduleEventAttributeBuilder
{
public static ScheduleEventAttribute Build(AttributeData att)
{
if (att.ConstructorArguments.Length != 1)
{
throw new NotSupportedException($"{TypeFullNames.ScheduleEventAttribute} must have constructor with 1 argument.");
}
var schedule = att.ConstructorArguments[0].Value as string;
var data = new ScheduleEventAttribute(schedule);
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.Description) && pair.Value.Value is string description)
{
data.Description = description;
}
else if (pair.Key == nameof(data.Input) && pair.Value.Value is string input)
{
data.Input = input;
}
else if (pair.Key == nameof(data.Enabled) && pair.Value.Value is bool enabled)
{
data.Enabled = enabled;
}
}
return data;
}
}
}