Terraria v1.4.4.9
Terraria source code documentation
All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Macros
CSharpHelpers.cs
Go to the documentation of this file.
3
4namespace System;
5
6internal abstract class CSharpHelpers
7{
9 {
10 "as", "do", "if", "in", "is", "for", "int", "new", "out", "ref",
11 "try", "base", "bool", "byte", "case", "char", "else", "enum", "goto", "lock",
12 "long", "null", "this", "true", "uint", "void", "break", "catch", "class", "const",
13 "event", "false", "fixed", "float", "sbyte", "short", "throw", "ulong", "using", "where",
14 "while", "yield", "double", "extern", "object", "params", "public", "return", "sealed", "sizeof",
15 "static", "string", "struct", "switch", "typeof", "unsafe", "ushort", "checked", "decimal", "default",
16 "finally", "foreach", "partial", "private", "virtual", "abstract", "continue", "delegate", "explicit", "implicit",
17 "internal", "operator", "override", "readonly", "volatile", "__arglist", "__makeref", "__reftype", "interface", "namespace",
18 "protected", "unchecked", "__refvalue", "stackalloc"
19 };
20
21 public static string CreateEscapedIdentifier(string name)
22 {
23 if (IsKeyword(name) || IsPrefixTwoUnderscore(name))
24 {
25 return "@" + name;
26 }
27 return name;
28 }
29
31 {
33 }
34
35 internal static bool IsKeyword(string value)
36 {
37 return s_fixedStringLookup.Contains(value);
38 }
39
40 internal static bool IsPrefixTwoUnderscore(string value)
41 {
42 if (value.Length < 3)
43 {
44 return false;
45 }
46 if (value[0] == '_' && value[1] == '_')
47 {
48 return value[2] != '_';
49 }
50 return false;
51 }
52
53 internal static bool IsValidTypeNameOrIdentifier(string value, bool isTypeName)
54 {
55 bool nextMustBeStartChar = true;
56 if (string.IsNullOrEmpty(value))
57 {
58 return false;
59 }
60 foreach (char c in value)
61 {
63 {
64 case UnicodeCategory.UppercaseLetter:
65 case UnicodeCategory.LowercaseLetter:
66 case UnicodeCategory.TitlecaseLetter:
67 case UnicodeCategory.ModifierLetter:
68 case UnicodeCategory.OtherLetter:
69 case UnicodeCategory.LetterNumber:
70 nextMustBeStartChar = false;
71 break;
72 case UnicodeCategory.NonSpacingMark:
73 case UnicodeCategory.SpacingCombiningMark:
74 case UnicodeCategory.DecimalDigitNumber:
75 case UnicodeCategory.ConnectorPunctuation:
76 if (nextMustBeStartChar && c != '_')
77 {
78 return false;
79 }
80 nextMustBeStartChar = false;
81 break;
82 default:
84 {
85 return false;
86 }
87 break;
88 }
89 }
90 return true;
91 }
92
93 internal static bool IsSpecialTypeChar(char ch, ref bool nextMustBeStartChar)
94 {
95 switch (ch)
96 {
97 case '$':
98 case '&':
99 case '*':
100 case '+':
101 case ',':
102 case '-':
103 case '.':
104 case ':':
105 case '<':
106 case '>':
107 case '[':
108 case ']':
109 nextMustBeStartChar = true;
110 return true;
111 case '`':
112 return true;
113 default:
114 return false;
115 }
116 }
117}
static readonly HashSet< string > s_fixedStringLookup
static string CreateEscapedIdentifier(string name)
static bool IsKeyword(string value)
static bool IsSpecialTypeChar(char ch, ref bool nextMustBeStartChar)
static bool IsValidTypeNameOrIdentifier(string value, bool isTypeName)
static bool IsValidLanguageIndependentIdentifier(string value)
static bool IsPrefixTwoUnderscore(string value)
static UnicodeCategory GetUnicodeCategory(char ch)