@@ -14,6 +14,20 @@ public static class StringExtensions
1414 static readonly Regex FIRST_CHAR_FOLLOWED_BY_UPPER_CASES_ONLY = new Regex ( "(?<=[A-Z])[A-Z0-9]+$" ) ;
1515 static readonly Regex LOWER_CASE_NEXT_TO_NUMBER = new Regex ( "(?<=[0-9])[a-z]" ) ;
1616 static readonly Regex UPPER_CASE_INSIDE = new Regex ( "(?<=[A-Z])[A-Z]+?((?=[A-Z][a-z])|(?=[0-9]))" ) ;
17+
18+ private static string [ ] RESERVED_KEYWORDS =
19+ {
20+ "abstract" , "as" , "base" , " bool" , " break" , "byte" , "case" , "catch" , "char" , "checked" , "class" , "const" ,
21+ "continue" , "decimal" , "default" , "delegate" , "do" , "double" , "else" , "enum" , "event" , "explicit" , "extern" ,
22+ "false" , "finally" , "fixed" , "float" , "for" , "foreach" , "goto" , "if" , "implicit" , "in" , "int" , "interface" ,
23+ "internal" , "is" , "lock" , "long" , "namespace" , "new" , "null" , "object" , "operator" , "out" , "override" ,
24+ "params" , "private" , "protected" , "public" , "readonly" , "ref" , "return" , "sbyte" , "sealed" , "short" ,
25+ "sizeof" , "stackalloc" , "static" , "string" , "struct" , "switch" , "this" , "throw" , "true" , "try" , "typeof" ,
26+ "uint" , "ulong" , "unchecked" , "unsafe" , "ushort" , "using" , "virtual" , "void" , "volatile" , "while" , "add" ,
27+ "alias" , "ascending" , "async" , "await" , "by" , "descending" , "dynamic" , "equals" , "from" , "get" , "global" ,
28+ "group" , "into" , "join" , "let" , "nameof" , "notnull" , "on" , "orderby" , "partial" , "partial" , "remove" ,
29+ "select" , "set" , "unmanaged" , "value" , "var" , "when" , "where" , "where" , "with" , "yield" , "values"
30+ } ;
1731
1832 public static string Sanitize ( this string input )
1933 {
@@ -123,5 +137,17 @@ public static string FirstToUpper(this string input)
123137 {
124138 return char . ToUpper ( input [ 0 ] ) + input . Substring ( 1 ) ;
125139 }
140+
141+ public static bool IsReservedKeyword ( this string targetName )
142+ {
143+ for ( int i = 0 ; i < RESERVED_KEYWORDS . Length ; i ++ )
144+ {
145+ string reservedKeyword = RESERVED_KEYWORDS [ i ] ;
146+ if ( reservedKeyword . Equals ( targetName , StringComparison . OrdinalIgnoreCase ) )
147+ return true ;
148+ }
149+
150+ return false ;
151+ }
126152 }
127153}
0 commit comments