diff --git a/ILSpy.BamlDecompiler/Rewrite/ConnectionIdRewritePass.cs b/ILSpy.BamlDecompiler/Rewrite/ConnectionIdRewritePass.cs index 8c09b42f9..f4435832a 100644 --- a/ILSpy.BamlDecompiler/Rewrite/ConnectionIdRewritePass.cs +++ b/ILSpy.BamlDecompiler/Rewrite/ConnectionIdRewritePass.cs @@ -27,6 +27,8 @@ using ICSharpCode.Decompiler.IL.Transforms; using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.Decompiler.Util; +using ILSpy.BamlDecompiler.Xaml; + namespace ILSpy.BamlDecompiler.Rewrite { internal class ConnectionIdRewritePass : IRewritePass @@ -128,7 +130,7 @@ namespace ILSpy.BamlDecompiler.Rewrite var events = new List(); switch (inst) { - case Block b: + case Block _: foreach (var node in ((Block)inst).Instructions) { FindEvents(node, events); } @@ -197,6 +199,7 @@ namespace ILSpy.BamlDecompiler.Rewrite if (ldftn.OpCode != OpCode.LdFtn && ldftn.OpCode != OpCode.LdVirtFtn) return false; handlerName = ((IInstructionWithMethodOperand)ldftn).Method.Name; + handlerName = XamlUtils.EscapeName(handlerName); return true; } diff --git a/ILSpy.BamlDecompiler/Xaml/XamlUtils.cs b/ILSpy.BamlDecompiler/Xaml/XamlUtils.cs index 4ad9d6830..81c160a89 100644 --- a/ILSpy.BamlDecompiler/Xaml/XamlUtils.cs +++ b/ILSpy.BamlDecompiler/Xaml/XamlUtils.cs @@ -73,5 +73,27 @@ namespace ILSpy.BamlDecompiler.Xaml { // (11700684 * 0.000001) != (11700684 / 1000000.0) => 11.700683999999999 != 11.700684 return reader.ReadInt32() / 1000000.0; } + + /// + /// Escape characters that cannot be used in XML. + /// + public static StringBuilder EscapeName(StringBuilder sb, string name) + { + foreach (char ch in name) { + if (char.IsWhiteSpace(ch) || char.IsControl(ch) || char.IsSurrogate(ch)) + sb.AppendFormat("\\u{0:x4}", (int)ch); + else + sb.Append(ch); + } + return sb; + } + + /// + /// Escape characters that cannot be displayed in the UI. + /// + public static string EscapeName(string name) + { + return EscapeName(new StringBuilder(name.Length), name).ToString(); + } } } \ No newline at end of file