diff --git a/ILSpy.BamlDecompiler/BamlResourceEntryNode.cs b/ILSpy.BamlDecompiler/BamlResourceEntryNode.cs index 9b0a515dd..30444af81 100644 --- a/ILSpy.BamlDecompiler/BamlResourceEntryNode.cs +++ b/ILSpy.BamlDecompiler/BamlResourceEntryNode.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; using System.Xml.Linq; using ICSharpCode.AvalonEdit.Highlighting; +using ICSharpCode.Decompiler.Util; using ICSharpCode.ILSpy; using ICSharpCode.ILSpy.TextView; using ICSharpCode.ILSpy.TreeNodes; @@ -135,7 +136,7 @@ namespace ILSpy.BamlDecompiler } } - static void RemoveConnectionIds(XElement element, Dictionary eventMappings) + static void RemoveConnectionIds(XElement element, List<(LongSet key, EventRegistration[] value)> eventMappings) { foreach (var child in element.Elements()) RemoveConnectionIds(child, eventMappings); @@ -143,10 +144,9 @@ namespace ILSpy.BamlDecompiler var removableAttrs = new List(); var addableAttrs = new List(); foreach (var attr in element.Attributes(XName.Get("ConnectionId", XmlBamlReader.XWPFNamespace))) { - int id; - if (int.TryParse(attr.Value, out id) && eventMappings.ContainsKey(id)) { - var map = eventMappings[id]; - foreach (var entry in map) { + int id, index; + if (int.TryParse(attr.Value, out id) && (index = eventMappings.FindIndex(item => item.key.Contains(id))) > -1) { + foreach (var entry in eventMappings[index].value) { string xmlns = ""; // TODO : implement xmlns resolver! addableAttrs.Add(new XAttribute(xmlns + entry.EventName, entry.MethodName)); } diff --git a/ILSpy.BamlDecompiler/ConnectMethodDecompiler.cs b/ILSpy.BamlDecompiler/ConnectMethodDecompiler.cs index 7c970ea54..a28f63d7b 100644 --- a/ILSpy.BamlDecompiler/ConnectMethodDecompiler.cs +++ b/ILSpy.BamlDecompiler/ConnectMethodDecompiler.cs @@ -10,6 +10,7 @@ using ICSharpCode.Decompiler.CSharp; using ICSharpCode.Decompiler.IL; using ICSharpCode.Decompiler.IL.Transforms; using ICSharpCode.Decompiler.TypeSystem; +using ICSharpCode.Decompiler.Util; using Mono.Cecil; namespace ILSpy.BamlDecompiler @@ -34,9 +35,9 @@ namespace ILSpy.BamlDecompiler this.assembly = assembly; } - public Dictionary DecompileEventMappings(string fullTypeName, CancellationToken cancellationToken) + public List<(LongSet, EventRegistration[])> DecompileEventMappings(string fullTypeName, CancellationToken cancellationToken) { - var result = new Dictionary(); + var result = new List<(LongSet, EventRegistration[])>(); TypeDefinition type = this.assembly.MainModule.GetType(fullTypeName); if (type == null) @@ -70,8 +71,7 @@ namespace ILSpy.BamlDecompiler if (ilSwitch != null) { foreach (var section in ilSwitch.Sections) { var events = FindEvents(section.Body); - foreach (long id in section.Labels.Values) - result.Add(id, events); + result.Add((section.Labels, events)); } } else { foreach (var ifInst in function.Descendants.OfType()) { @@ -82,7 +82,7 @@ namespace ILSpy.BamlDecompiler if (!comp.Right.MatchLdcI4(out id)) continue; var events = FindEvents(comp.Kind == ComparisonKind.Inequality ? ifInst.FalseInst : ifInst.TrueInst); - result.Add(id, events); + result.Add((new LongSet(id), events)); } } return result;