Beispiel #1
0
 // we are not sure if this is vb or csharp project. So escape both.
 internal static string EscapeName(string identifierName)
 {
     using (CSharpCodeProvider cSharpCodeProvider = new CSharpCodeProvider())
     {
         identifierName = cSharpCodeProvider.CreateEscapedIdentifier(identifierName);
     }
     return(identifierName);
 }
Beispiel #2
0
        /// <summary>
        /// Returns a string that is safe for use as an identifier in C#.
        /// Keywords are escaped.
        /// </summary>
        public string Escape(string name)
        {
            if (name == null)
            {
                return(null);
            }

            return(_code.CreateEscapedIdentifier(name));
        }
Beispiel #3
0
 public string GenerateValidToken(string token)
 {
     using (var code = new CSharpCodeProvider())
     {
         token = code.CreateEscapedIdentifier(token);
         var validToken = token;
         var salt       = 0;
         do
         {
             validToken = Tokens.Contains(validToken)
                 ? string.Format("{0}{1}", token, salt)
                 : token;
             salt++;
         } while (!string.IsNullOrWhiteSpace(validToken) && Tokens.Contains(validToken));
         Tokens.Add(validToken);
         return(validToken);
     }
 }
Beispiel #4
0
        private string getFormalParamName(MessageParser.FieldDefinition field)
        {
            var name = string.Format("{0}{1}", field.Name.First().ToString().ToLower(), field.Name.Substring(1, field.Name.Length - 1));

            return(cs.CreateEscapedIdentifier(name));
        }