public override void EnsureTagStorage() { var systemObject = _referenceFinder.GetTypeReference(typeof(object)); _tagField = _module.ImportReference(_stateMachine.AddPublicInstanceField(systemObject)); TagPersistable = new FieldPersistable(new VariablePersistable(_stateMachineLocal), _tagField); }
protected override void WeaveMethodExecutionArgs(NamedInstructionBlockChain arguments) { var executionArgs = _creator.CreateMethodExecutionArgsInstance( arguments, _aspects[0].Info.AspectAttribute.AttributeType); _executionArgsField = _module.ImportReference(_stateMachine.AddPublicInstanceField(executionArgs.Variable.VariableType)); executionArgs.Add(new InstructionBlock("", Instruction.Create(OpCodes.Ldloc, executionArgs.Variable))); var field = new FieldPersistable(new VariablePersistable(_stateMachineLocal), _executionArgsField); var instructions = field.Store(executionArgs.Flatten(), _module.ImportReference(typeof(void))); var chain = new InstructionBlockChain(); chain.Add(instructions); AddToSetup(chain); ExecutionArgs = field; }
public override InstructionBlockChain CreateAspectInstance() { var aspectTypeReference = _module.ImportReference(Info.AspectAttribute.AttributeType); _aspectField = _module.ImportReference(_stateMachine.AddPublicInstanceField(aspectTypeReference)); var loadMachine = new VariablePersistable(_stateMachineLocal).Load(true); var newObjectAspectBlock = _creator.CreateAndNewUpAspect(Info.AspectAttribute); var loadOnStack = new InstructionBlock("Load on stack", Instruction.Create(OpCodes.Ldloc, newObjectAspectBlock.Variable)); var storeField = new InstructionBlock("Store Field", Instruction.Create(OpCodes.Stfld, _aspectField)); var newObjectAspectBlockChain = new InstructionBlockChain(); newObjectAspectBlockChain.Add(loadMachine); newObjectAspectBlockChain.Add(newObjectAspectBlock); newObjectAspectBlockChain.Add(loadOnStack); newObjectAspectBlockChain.Add(storeField); AspectPersistable = new FieldPersistable(new VariablePersistable(_stateMachineLocal), _aspectField); return(newObjectAspectBlockChain); }
public InstructionBlockChain CallOnExceptionInMoveNext(IPersistable executionArgs, VariableDefinition exceptionLocal) { var onExceptionMethodRef = _referenceFinder.GetMethodReference(Info.AspectAttribute.AttributeType, md => md.Name == "OnException"); var setMethod = _referenceFinder.GetMethodReference(executionArgs.PersistedType, md => md.Name == "set_Exception"); var setExceptionOnArgsBlock = _creator.CallVoidMethod(setMethod, GetMoveNextExecutionArgs(executionArgs), new VariablePersistable(exceptionLocal)); var sm = StateMachineFromMoveNext; var smPersistable = new ThisLoadable(sm); var aspectPersistable = new FieldPersistable(smPersistable, _aspectField.AsDefinedOn(sm)); var callOnExceptionBlock = _creator.CallVoidMethod(onExceptionMethodRef, aspectPersistable, GetMoveNextExecutionArgs(executionArgs)); var callAspectOnExceptionBlockChain = new InstructionBlockChain(); callAspectOnExceptionBlockChain.Add(setExceptionOnArgsBlock); callAspectOnExceptionBlockChain.Add(callOnExceptionBlock); return(callAspectOnExceptionBlockChain); }