diff --git a/ILSpy/ConnectMethodDecompiler.cs b/ILSpy/ConnectMethodDecompiler.cs index 2bf9aba3c..5e60c68e5 100644 --- a/ILSpy/ConnectMethodDecompiler.cs +++ b/ILSpy/ConnectMethodDecompiler.cs @@ -58,24 +58,41 @@ namespace ICSharpCode.ILSpy.Baml var context = new DecompilerContext(type.Module) { CurrentMethod = def, CurrentType = type }; optimizer.Optimize(context, ilMethod, ILAstOptimizationStep.RemoveRedundantCode3); - var cases = ilMethod.Body.OfType().First().CaseBlocks; + ILSwitch ilSwitch = ilMethod.Body.OfType().FirstOrDefault(); + ILCondition condition = ilMethod.Body.OfType().FirstOrDefault(); - foreach (var caseBlock in cases) { - if (caseBlock.Values == null) - continue; - var events = new List(); - foreach (var node in caseBlock.Body) { - var expr = node as ILExpression; - string eventName, handlerName; - if (IsAddEvent(expr, out eventName, out handlerName)) - events.Add(new EventRegistration() { EventName = eventName, MethodName = handlerName }); + if (ilSwitch != null) { + foreach (var caseBlock in ilSwitch.CaseBlocks) { + if (caseBlock.Values == null) + continue; + var events = FindEvents(caseBlock); + foreach (int id in caseBlock.Values) + result.Add(id, events); } - foreach (int id in caseBlock.Values) - result.Add(id, events.ToArray()); + } else if (condition != null) { + result.Add(1, FindEvents(condition.FalseBlock)); } return result; } + + EventRegistration[] FindEvents(ILBlock block) + { + var events = new List(); + + foreach (var node in block.Body) { + var expr = node as ILExpression; + string eventName, handlerName; + if (IsAddEvent(expr, out eventName, out handlerName)) + events.Add(new EventRegistration { + EventName = eventName, + MethodName = handlerName + }); + // TODO : handle attached events + } + + return events.ToArray(); + } bool IsAddEvent(ILExpression expr, out string eventName, out string handlerName) {