private void AddLocalVariables(MethodDefinition method, ILProcessor processor, IWeavingPlan plan)
        {
            var instructions = new List <Instruction>();

            // ordering of declarations of the local variables matters when applying switches in the end
            if (plan.NeedContextVariable())
            {
                AddExecutionContextVariable(method, instructions, processor);
            }

            if (plan.NeedExecutionVariable())
            {
                AddExecutionVariable(method, instructions, processor);
            }

            if (plan.NeedExceptionVariable())
            {
                AddExceptionVariable(method);
            }

            if (plan.NeedReturnVariable())
            {
                AddReturnVariable(method, instructions, processor);
            }

            if (NeedToStoreReturnValueAsLocalVariable(method, plan))
            {
                AddReturnValueVariable(method);
            }

            if (NeedHasExceptionVariable(method, plan))
            {
                AddHasExceptionVariable(method, instructions, processor);
            }

            CompleteAddingLocalVariableInstructions(method, instructions, processor);
        }
 private static bool NeedHasExceptionVariable(MethodDefinition method, IWeavingPlan plan) => plan.NeedHasExceptionVariable() || (plan.NeedReturnVariable() && !method.IsVoidReturn());