/// <summary> /// Emits the handler method addition, done at end of parsing, Loc_0 is root node instance /// </summary> /// <param name="bd">Bd.</param> /// <param name="evt">passed as arg to prevent refetching it for the 3rd time</param> public void emitHandlerMethodAddition(EventBinding bd) { //fetch source instance with address for handler addition (as 1st arg of handler.add) il.Emit(OpCodes.Ldloc_0); //push root CompilerServices.emitGetInstance(il, bd.SourceNA); il.Emit(OpCodes.Ldloc_0); CompilerServices.emitGetInstance(il, bd.TargetNA); string[] membs = bd.TargetMember.Split('.'); for (int i = 0; i < membs.Length - 1; i++) { il.Emit(OpCodes.Dup); il.Emit(OpCodes.Ldstr, membs[i]); il.Emit(OpCodes.Call, CompilerServices.miGetMembIinfoWithRefx); il.Emit(OpCodes.Call, CompilerServices.miGetValWithRefx); } //load handlerType of sourceEvent to create handler delegate (1st arg) il.Emit(OpCodes.Ldtoken, bd.SourceEvent.EventHandlerType); il.Emit(OpCodes.Call, CompilerServices.miGetTypeFromHandle); //load methodInfo (3rd arg) il.Emit(OpCodes.Ldstr, membs[membs.Length - 1]); il.Emit(OpCodes.Callvirt, CompilerServices.miCreateDel); il.Emit(OpCodes.Callvirt, bd.SourceEvent.AddMethod); //call add event }
/// <summary> /// Emits cached delegate handler addition in the context of instantiator (ctx) /// </summary> public void emitCachedDelegateHandlerAddition(int index, EventInfo evt, NodeAddress address = null) { il.Emit(OpCodes.Ldloc_0); //load ref to current graphic object CompilerServices.emitGetInstance(il, address); il.Emit(OpCodes.Ldarg_0); //load ref to this instanciator onto the stack il.Emit(OpCodes.Ldfld, CompilerServices.fiCachedDel); il.Emit(OpCodes.Ldc_I4, index); //load delegate index il.Emit(OpCodes.Callvirt, CompilerServices.miGetDelegateListItem); il.Emit(OpCodes.Callvirt, evt.AddMethod); //call add event }
/// <summary> /// Emits the handler method addition, done at end of parsing, Loc_0 is root node instance /// </summary> /// <param name="bd">Bd.</param> /// <param name="evt">passed as arg to prevent refetching it for the 3rd time</param> public void emitHandlerMethodAddition(EventBinding bd) { //fetch source instance with address for handler addition (as 1st arg of handler.add) il.Emit(OpCodes.Ldloc_0); //push root CompilerServices.emitGetInstance(il, bd.SourceNA); //load handlerType of sourceEvent to create handler delegate (1st arg) il.Emit(OpCodes.Ldtoken, bd.SourceEvent.EventHandlerType); il.Emit(OpCodes.Call, CompilerServices.miGetTypeFromHandle); //load target the where the method is defined (2nd arg) il.Emit(OpCodes.Ldloc_0); CompilerServices.emitGetInstance(il, bd.TargetNA); //load methodInfo (3rd arg) il.Emit(OpCodes.Ldstr, bd.TargetMember); il.Emit(OpCodes.Callvirt, CompilerServices.miCreateDel); il.Emit(OpCodes.Callvirt, bd.SourceEvent.AddMethod); //call add event }