CSharpSourceEmitter.SourceEmitter.EscapeIdentifier C# (CSharp) Method

EscapeIdentifier() public static method

public static EscapeIdentifier ( string identifier ) : string
identifier string
return string
    public static string EscapeIdentifier(string identifier) {
      // Check to see if this is a keyword, and if so escape it with '@' prefix
      switch (identifier) {
        case "abstract":   case "as":          case "base":      case "bool":      case "break":
        case "byte":       case "case":        case "catch":     case "char":      case "checked":     case "class":
        case "const":      case "continue":    case "decimal":   case "default":   case "delegate":    case "do":
        case "double":     case "else":        case "enum":      case "event":     case "explicit":    case "extern":
        case "false":      case "finally":     case "fixed":     case "float":     case "for":         case "foreach":
        case "goto":       case "if":          case "implicit":  case "in":        case "int":         case "interface":
        case "internal":   case "is":          case "lock":      case "long":      case "namespace":   case "new":
        case "null":       case "object":      case "operator":  case "out":       case "override":    case "params":
        case "private":    case "protected":   case "public":    case "readonly":  case "ref":         case "return":
        case "sbyte":      case "sealed":      case "short":     case "sizeof":    case "stackalloc":  case "static":
        case "string":     case "struct":      case "switch":    case "this":      case "throw":       case "true":
        case "try":        case "typeof":      case "uint":      case "ulong":     case "unchecked":   case "unsafe":
        case "ushort":     case "using":       case "virtual":   case "void":      case "volatile":    case "while":
          return "@" + identifier;
      }

      // Not a keyword, just return it
      // It may still have characters that are invalid for an identifier, but C# doesn't provide any way to
      // escape those (even unicode escapes must conform to the required character classes)
      return identifier;
    }
SourceEmitter