-
Notifications
You must be signed in to change notification settings - Fork 384
/
Copy pathValueFormRegistry.cs
57 lines (49 loc) · 2.32 KB
/
ValueFormRegistry.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.TemplateEngine.Orchestrator.RunnableProjects.ValueForms;
using Newtonsoft.Json.Linq;
namespace Microsoft.TemplateEngine.Orchestrator.RunnableProjects
{
internal static class ValueFormRegistry
{
private static readonly IReadOnlyList<IValueFormFactory> AllForms =
new IValueFormFactory[]
{
new ReplacementValueFormFactory(),
new ChainValueFormFactory(),
new XmlEncodeValueFormFactory(),
new JsonEncodeValueFormFactory(),
new IdentityValueFormFactory(),
new DefaultSafeNameValueFormFactory(),
new DefaultLowerSafeNameValueFormFactory(),
new DefaultSafeNamespaceValueFormFactory(),
new DefaultLowerSafeNamespaceValueFormFactory(),
new LowerCaseValueFormFactory(),
new LowerCaseInvariantValueFormFactory(),
new UpperCaseValueFormFactory(),
new UpperCaseInvariantValueFormFactory(),
new FirstLowerCaseValueFormFactory(),
new FirstUpperCaseValueFormFactory(),
new FirstUpperCaseInvariantValueFormFactory(),
new FirstLowerCaseInvariantValueFormFactory(),
new KebabCaseValueFormFactory(),
new SnakeCaseValueFormFactory(),
new TitleCaseValueFormFactory(),
};
private static readonly IValueFormFactory DefaultForm = new IdentityValueFormFactory();
internal static IReadOnlyDictionary<string, IValueFormFactory> FormLookup => AllForms.ToDictionary(ff => ff.Identifier, ff => ff, StringComparer.OrdinalIgnoreCase);
internal static IValueForm GetForm(string name, JObject? obj)
{
string? identifier = obj.ToString("identifier");
if (string.IsNullOrWhiteSpace(identifier))
{
return DefaultForm.FromJObject(name, obj);
}
if (!FormLookup.TryGetValue(identifier!, out IValueFormFactory? value))
{
return DefaultForm.FromJObject(name, obj);
}
return value.FromJObject(name, obj);
}
}
}