-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathHelpers.cs
More file actions
126 lines (118 loc) · 3.76 KB
/
Helpers.cs
File metadata and controls
126 lines (118 loc) · 3.76 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using System.Text.RegularExpressions;
namespace Linq2GraphQL.Generator;
public static class Helpers
{
internal static string SummarySafe(string text)
{
if (string.IsNullOrEmpty(text)) { return text; }
return Regex.Replace(text, @"\r\n?|\n", Environment.NewLine + "/// ");
}
internal static string SafeDeprecationReason(string text)
{
if (string.IsNullOrEmpty(text)) { return text; }
return text.Replace("\"", "'");
}
internal static string SafeVariableName(string name)
{
if (string.IsNullOrEmpty(name)) { return name; }
var newName = name.ToCamelCase();
if (Keywords.Contains(newName)) { return "@" + newName; }
return newName;
}
public static readonly HashSet<string> Keywords = [
"abstract",
"as",
"base",
"bool",
"break",
"byte",
"case",
"catch",
"char",
"checked",
"class",
"const",
"continue",
"decimal",
"default",
"delegate",
"do",
"double",
"else",
"enum",
"event",
"explicit",
"extern",
"false",
"finally",
"fixed",
"float",
"for",
"foreach",
"goto",
"if",
"implicit",
"in",
"int",
"interface",
"internal",
"is",
"lock",
"long",
"namespace",
"new",
"null",
"object",
"operator",
"out",
"override",
"params",
"private",
"protected",
"public",
"readonly",
"ref",
"return",
"sbyte",
"sealed",
"short",
"sizeof",
"static",
"string",
"struct",
"switch",
"this",
"throw",
"true",
"try",
"typeof",
"uint",
"ulong",
"unchecked",
"unsafe",
"ushort",
"using",
"virtual",
"void",
"volatile",
"while",];
public static readonly Dictionary<string, (string Name, Type type)> TypeMapping =
new(StringComparer.InvariantCultureIgnoreCase)
{
{ "Int", new ValueTuple<string, Type>("int", typeof(int)) },
{ "Float", new ValueTuple<string, Type>("double", typeof(double)) },
{ "String", new ValueTuple<string, Type>("string", typeof(string)) },
{ "Date", new ValueTuple<string, Type>("DateTime", typeof(DateTime)) },
{ "Boolean", new ValueTuple<string, Type>("bool", typeof(bool)) },
{ "Long", new ValueTuple<string, Type>("long", typeof(long)) },
{ "uuid", new ValueTuple<string, Type>("Guid", typeof(Guid)) },
{ "timestamptz", new ValueTuple<string, Type>("DateTimeOffset", typeof(DateTimeOffset)) },
{ "Uri", new ValueTuple<string, Type>("Uri", typeof(Uri)) },
{ "DateTime", new ValueTuple<string, Type>("DateTimeOffset", typeof(DateTimeOffset)) },
{ "Decimal", new ValueTuple<string, Type>("decimal", typeof(decimal)) },
{ "TimeSpan", new ValueTuple<string, Type>("TimeSpan", typeof(TimeSpan)) },
{ "Byte", new ValueTuple<string, Type>("byte", typeof(byte)) },
{ "LocalDate", new ValueTuple<string, Type>("DateOnly", typeof(DateOnly)) },
{ "LocalTime", new ValueTuple<string, Type>("TimeOnly", typeof(TimeOnly)) },
};
}