From c6ce6d3d007c291774c7f3b2f5d683b6113370a7 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 6 Jun 2016 09:30:26 +0900 Subject: [PATCH] prefix identifiers starting with invalid characters with an underscore --- .../CSharp/Transforms/EscapeInvalidIdentifiers.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler/CSharp/Transforms/EscapeInvalidIdentifiers.cs b/ICSharpCode.Decompiler/CSharp/Transforms/EscapeInvalidIdentifiers.cs index 868adb6fc..fd2636ea3 100644 --- a/ICSharpCode.Decompiler/CSharp/Transforms/EscapeInvalidIdentifiers.cs +++ b/ICSharpCode.Decompiler/CSharp/Transforms/EscapeInvalidIdentifiers.cs @@ -40,7 +40,10 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms string ReplaceInvalid(string s) { - return string.Concat(s.Select(ch => IsValid(ch) ? ch.ToString() : string.Format("_{0:X4}", (int)ch))); + string name = string.Concat(s.Select(ch => IsValid(ch) ? ch.ToString() : string.Format("_{0:X4}", (int)ch))); + if (name.Length >= 1 && !(char.IsLetter(name[0]) || name[0] == '_')) + name = "_" + name; + return name; } public void Run(AstNode rootNode, TransformContext context)