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
use heck::{ToLowerCamelCase, ToUpperCamelCase};
pub(crate) trait ToCSharpIdent: ToOwned {
fn csharp_keywords() -> &'static [&'static str];
fn to_csharp_ident(&self) -> Self::Owned;
fn to_csharp_ident_upper(&self) -> Self::Owned;
}
impl ToCSharpIdent for str {
// Source: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/
fn csharp_keywords() -> &'static [&'static str] {
static CSHARP_KEY_WORDS: &[&str] = &[
"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",
"stackalloc",
"static",
"string",
"struct",
"switch",
"this",
"throw",
"true",
"try",
"typeof",
"uint",
"ulong",
"unchecked",
"unsafe",
"ushort",
"using",
"virtual",
"void",
"volatile",
"while",
];
CSHARP_KEY_WORDS
}
fn to_csharp_ident(&self) -> String {
// Escape C# keywords
if Self::csharp_keywords().contains(&self) {
format!("@{self}")
} else {
self.to_lower_camel_case()
}
}
fn to_csharp_ident_upper(&self) -> String {
// Escape C# keywords
if Self::csharp_keywords().contains(&self) {
format!("@{self}")
} else {
self.to_upper_camel_case()
}
}
}