private static Instruction FindNextConstructionMethod(MethodDefinition method, Instruction instruction) { var cursor = instruction; //the description object should be on the stack, and nothing on top of it. int stackDepth = 1; while (cursor.Next != null) { cursor = cursor.Next; var result = CecilHelpers.MatchesDelegateProducingPattern(method, cursor, CecilHelpers.DelegateProducingPattern.MatchSide.Start); if (result != null) { cursor = result.Instructions.Last(); stackDepth += 1; continue; } if (CecilHelpers.IsUnsupportedBranch(cursor)) { UserError.DC0010(method, cursor).Throw(); } if (cursor.OpCode == OpCodes.Call && cursor.Operand is MethodReference mr && IsLambdaJobDescriptionConstructionMethod(mr)) { return(cursor); } stackDepth -= cursor.GetPopDelta(); if (stackDepth < 1) { UserError.DC0011(method, cursor).Throw(); } stackDepth += cursor.GetPushDelta(); } return(null); }