diff --git a/crates/csharp/src/lib.rs b/crates/csharp/src/lib.rs index 6f71610ce..7f148e40d 100644 --- a/crates/csharp/src/lib.rs +++ b/crates/csharp/src/lib.rs @@ -2584,20 +2584,27 @@ trait ToCSharpIdent: ToOwned { impl ToCSharpIdent for str { fn to_csharp_ident(&self) -> String { - // Escape C# keywords - // Source: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/ - - //TODO: Repace with actual keywords - match self { - "abstract" | "continue" | "for" | "new" | "switch" | "assert" | "default" | "goto" - | "namespace" | "synchronized" | "boolean" | "do" | "if" | "private" | "this" - | "break" | "double" | "implements" | "protected" | "throw" | "byte" | "else" - | "import" | "public" | "throws" | "case" | "enum" | "instanceof" | "return" - | "transient" | "catch" | "extends" | "int" | "short" | "try" | "char" | "final" - | "interface" | "static" | "void" | "class" | "finally" | "long" | "strictfp" - | "volatile" | "const" | "float" | "super" | "while" | "extern" | "sizeof" | "type" - | "struct" => format!("@{self}"), - _ => self.to_lower_camel_case(), + let ident = self.to_lower_camel_case(); + match ident.as_str() { + // Escape C# keywords + // Source: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/ + "abstract" | "as" | "base" | "bool" | "break" | "byte" | "case" | "catch" | "char" + | "checked" | "class" | "const" | "continue" | "decimal" | "default" | "delegate" + | "do" | "double" | "else" | "enum" | "event" | "explicit" | "extern" | "false" + | "finally" | "fixed" | "float" | "for" | "foreach" | "goto" | "if" | "implicit" + | "in" | "int" | "interface" | "internal" | "is" | "lock" | "long" | "namespace" + | "new" | "null" | "object" | "operator" | "out" | "override" | "params" + | "private" | "protected" | "public" | "readonly" | "ref" | "return" | "sbyte" + | "sealed" | "short" | "sizeof" | "stackalloc" | "static" | "string" | "struct" + | "switch" | "this" | "throw" | "true" | "try" | "typeof" | "uint" | "ulong" + | "unchecked" | "unsafe" | "ushort" | "using" | "virtual" | "void" | "volatile" + | "while" | "add" | "and" | "alias" | "ascending" | "args" | "async" | "await" + | "by" | "descending" | "dynamic" | "equals" | "file" | "from" | "get" | "global" + | "group" | "init" | "into" | "join" | "let" | "managed" | "nameof" | "nint" + | "not" | "notnull" | "nuint" | "on" | "or" | "orderby" | "partial" | "record" + | "remove" | "required" | "scoped" | "select" | "set" | "unmanaged" | "value" + | "var" | "when" | "where" | "with" | "yield" => format!("@{ident}"), + _ => ident, } } }