Example #1
0
        public InstructionBlockChain IfFlowBehaviorIsAnyOf(Func <TypeReference, VariableDefinition> variableFactory, ILoadable args, Instruction nextInstruction, InstructionBlockChain thenBody, params int[] behaviors)
        {
            var typeRef             = args.PersistedType.Resolve();
            var getFlowBehavior     = _referenceFinder.GetMethodReference(typeRef, m => m.Name == "get_FlowBehavior");
            var flowBehaviorLocal   = new VariablePersistable(variableFactory(_moduleDefinition.ImportReference(getFlowBehavior.ReturnType)));
            var flowBehaviorHandler = CallMethodWithReturn(getFlowBehavior, args, flowBehaviorLocal);

            if (behaviors.Length == 0)
            {
                return(flowBehaviorHandler);
            }
            for (var i = 0; i < behaviors.Length - 1; ++i)
            {
                flowBehaviorHandler.Add(flowBehaviorLocal.Load(false, false));
                flowBehaviorHandler.Add(new InstructionBlock("FlowBehavior", Instruction.Create(OpCodes.Ldc_I4, behaviors[i])));
                flowBehaviorHandler.Add(new InstructionBlock("If == then goto the 'then' block", Instruction.Create(OpCodes.Beq_S, thenBody.First)));
            }

            flowBehaviorHandler.Add(flowBehaviorLocal.Load(false, false));
            flowBehaviorHandler.Add(new InstructionBlock("FlowBehavior", Instruction.Create(OpCodes.Ldc_I4, behaviors[behaviors.Length - 1])));
            flowBehaviorHandler.Add(new InstructionBlock("If != then skip", Instruction.Create(OpCodes.Bne_Un, nextInstruction)));

            flowBehaviorHandler.Add(thenBody);

            return(flowBehaviorHandler);
        }