-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathInstanceAPIGeneratorConfigBuilder.cs
38 lines (33 loc) · 1.24 KB
/
InstanceAPIGeneratorConfigBuilder.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
using System.Collections.Immutable;
namespace InstantAPIs.Generators.Helpers
{
public sealed class InstanceAPIGeneratorConfigBuilder<T>
where T : struct, Enum
{
private readonly Dictionary<T, TableConfig<T>> _tablesConfig = new();
public InstanceAPIGeneratorConfigBuilder()
{
foreach(var key in Enum.GetValues<T>())
{
_tablesConfig.Add(key, new TableConfig<T>(key));
}
}
public InstanceAPIGeneratorConfigBuilder<T> Include(T key, string? name = null, ApisToGenerate apis = ApisToGenerate.All,
Func<string?, string>? routeGet = null, Func<string?, string>? routeGetById = null,
Func<string?, string>? routePost = null, Func<string?, string>? routePut = null,
Func<string?, string>? routeDeleteById = null)
{
_tablesConfig[key] = new TableConfig<T>(key, Included.Yes, name: name,
apis: apis, routeGet: routeGet, routeGetById: routeGetById,
routePost: routePost, routePut: routePut, routeDeleteById: routeDeleteById);
return this;
}
public InstanceAPIGeneratorConfigBuilder<T> Exclude(T key)
{
_tablesConfig[key] = new TableConfig<T>(key, Included.No);
return this;
}
public InstanceAPIGeneratorConfig<T> Build() =>
new InstanceAPIGeneratorConfig<T>(_tablesConfig.ToImmutableDictionary());
}
}