@@ -25,31 +25,89 @@ public string ToFunctionName(string name)
25
25
26
26
public bool IsValidIdentifier ( string identifier )
27
27
{
28
- if ( String . IsNullOrEmpty ( identifier ) ) return false ;
28
+ if ( String . IsNullOrEmpty ( identifier ) )
29
+ return false ;
29
30
30
31
// C# keywords: http://msdn.microsoft.com/en-us/library/x53a06bb(v=vs.71).aspx
31
32
var keywords = new [ ]
32
33
{
33
- "abstract" , "event" , "new" , "struct" ,
34
- "as" , "explicit" , "null" , "switch" ,
35
- "base" , "extern" , "object" , "this" ,
36
- "bool" , "false" , "operator" , "throw" ,
37
- "breal" , "finally" , "out" , "true" ,
38
- "byte" , "fixed" , "override" , "try" ,
39
- "case" , "float" , "params" , "typeof" ,
40
- "catch" , "for" , "private" , "uint" ,
41
- "char" , "foreach" , "protected" , "ulong" ,
42
- "checked" , "goto" , "public" , "unchekeced" ,
43
- "class" , "if" , "readonly" , "unsafe" ,
44
- "const" , "implicit" , "ref" , "ushort" ,
45
- "continue" , "in" , "return" , "using" ,
46
- "decimal" , "int" , "sbyte" , "virtual" ,
47
- "default" , "interface" , "sealed" , "volatile" ,
48
- "delegate" , "internal" , "short" , "void" ,
49
- "do" , "is" , "sizeof" , "while" ,
50
- "double" , "lock" , "stackalloc" ,
51
- "else" , "long" , "static" ,
52
- "enum" , "namespace" , "string"
34
+ "abstract" ,
35
+ "event" ,
36
+ "new" ,
37
+ "struct" ,
38
+ "as" ,
39
+ "explicit" ,
40
+ "null" ,
41
+ "switch" ,
42
+ "base" ,
43
+ "extern" ,
44
+ "object" ,
45
+ "this" ,
46
+ "bool" ,
47
+ "false" ,
48
+ "operator" ,
49
+ "throw" ,
50
+ "breal" ,
51
+ "finally" ,
52
+ "out" ,
53
+ "true" ,
54
+ "byte" ,
55
+ "fixed" ,
56
+ "override" ,
57
+ "try" ,
58
+ "case" ,
59
+ "float" ,
60
+ "params" ,
61
+ "typeof" ,
62
+ "catch" ,
63
+ "for" ,
64
+ "private" ,
65
+ "uint" ,
66
+ "char" ,
67
+ "foreach" ,
68
+ "protected" ,
69
+ "ulong" ,
70
+ "checked" ,
71
+ "goto" ,
72
+ "public" ,
73
+ "unchekeced" ,
74
+ "class" ,
75
+ "if" ,
76
+ "readonly" ,
77
+ "unsafe" ,
78
+ "const" ,
79
+ "implicit" ,
80
+ "ref" ,
81
+ "ushort" ,
82
+ "continue" ,
83
+ "in" ,
84
+ "return" ,
85
+ "using" ,
86
+ "decimal" ,
87
+ "int" ,
88
+ "sbyte" ,
89
+ "virtual" ,
90
+ "default" ,
91
+ "interface" ,
92
+ "sealed" ,
93
+ "volatile" ,
94
+ "delegate" ,
95
+ "internal" ,
96
+ "short" ,
97
+ "void" ,
98
+ "do" ,
99
+ "is" ,
100
+ "sizeof" ,
101
+ "while" ,
102
+ "double" ,
103
+ "lock" ,
104
+ "stackalloc" ,
105
+ "else" ,
106
+ "long" ,
107
+ "static" ,
108
+ "enum" ,
109
+ "namespace" ,
110
+ "string"
53
111
} ;
54
112
55
113
// definition of a valid C# identifier: http://msdn.microsoft.com/en-us/library/aa664670(v=vs.71).aspx
@@ -58,15 +116,10 @@ public bool IsValidIdentifier(string identifier)
58
116
const string decimalDigitCharacter = @"\p{Nd}" ;
59
117
const string combiningCharacter = @"\p{Mn}|\p{Mc}" ;
60
118
const string letterCharacter = @"\p{Lu}|\p{Ll}|\p{Lt}|\p{Lm}|\p{Lo}|\p{Nl}" ;
61
- const string identifierPartCharacter = letterCharacter + "|" +
62
- decimalDigitCharacter + "|" +
63
- connectingCharacter + "|" +
64
- combiningCharacter + "|" +
65
- formattingCharacter ;
119
+ const string identifierPartCharacter = letterCharacter + "|" + decimalDigitCharacter + "|" + connectingCharacter + "|" + combiningCharacter + "|" + formattingCharacter ;
66
120
const string identifierPartCharacters = "(" + identifierPartCharacter + ")+" ;
67
121
const string identifierStartCharacter = "(" + letterCharacter + "|_)" ;
68
- const string identifierOrKeyword = identifierStartCharacter + "(" +
69
- identifierPartCharacters + ")*" ;
122
+ const string identifierOrKeyword = identifierStartCharacter + "(" + identifierPartCharacters + ")*" ;
70
123
var validIdentifierRegex = new Regex ( "^" + identifierOrKeyword + "$" , RegexOptions . Compiled ) ;
71
124
var normalizedIdentifier = identifier . Normalize ( ) ;
72
125
@@ -123,14 +176,14 @@ public void CompleteCodeBlocks()
123
176
}
124
177
125
178
protected abstract void DoWrite ( ) ;
126
-
179
+
127
180
public abstract string Filename { get ; }
128
181
129
182
public string Write ( bool force = false )
130
183
{
131
184
if ( ! string . IsNullOrWhiteSpace ( _cachedString ) && ! force )
132
185
return _cachedString ;
133
-
186
+
134
187
DoWrite ( ) ;
135
188
136
189
_cachedString = builder . ToString ( ) ;
@@ -142,7 +195,7 @@ public Dictionary<string, string> GenerateAll()
142
195
{
143
196
var dict = new Dictionary < string , string > ( ) ;
144
197
dict . Add ( Filename , ToString ( ) ) ;
145
-
198
+
146
199
// Add any additional files
147
200
foreach ( var generator in _context . Generators )
148
201
{
@@ -152,9 +205,9 @@ public Dictionary<string, string> GenerateAll()
152
205
return dict ;
153
206
}
154
207
155
- public string ToString ( )
208
+ public override string ToString ( )
156
209
{
157
210
return Write ( ) ;
158
211
}
159
212
}
160
- }
213
+ }
0 commit comments