From: jpbruyere Date: Fri, 16 Dec 2016 17:46:22 +0000 (+0100) Subject: emitHandlerBinding for oot template X-Git-Tag: v0.5.1~63^2~26 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=d7a793042bbb8f19839ef6af33b37c03788e5f80;p=jp%2Fcrow.git emitHandlerBinding for oot template --- diff --git a/src/Instantiator.cs b/src/Instantiator.cs index bfb63b81..812680e9 100644 --- a/src/Instantiator.cs +++ b/src/Instantiator.cs @@ -750,10 +750,19 @@ namespace Crow } void emitHandlerBinding (Context ctx, EventInfo sourceEvent, string expression){ - string[] bindingExp = expression.Split ('/'); + string memberName, namedNode; + NodeAddress currentNode = ctx.CurrentNodeAddress, targetNA; + + splitBindingExp (currentNode, expression, out targetNA, out memberName, out namedNode); - if (bindingExp.Length == 1) { - //datasource handler + string bindOnEventName = null; + + if (targetNA == null)//datasource handler + bindOnEventName = "DataSourceChanged"; + else if (targetNA.Count == 0)//out of tree template handler + bindOnEventName = "ParentChanged"; + + if (!string.IsNullOrEmpty(bindOnEventName)){ //we need to bind datasource method to source event DynamicMethod dm = new DynamicMethod ("dyn_dschangedForHandler", typeof (void), @@ -768,7 +777,7 @@ namespace Crow //fetch method in datasource and test if it exist il.Emit (OpCodes.Ldarg_2);//load new datasource il.Emit (OpCodes.Ldfld, CompilerServices.fiDSCNewDS); - il.Emit (OpCodes.Ldstr, bindingExp[0]);//load handler method name + il.Emit (OpCodes.Ldstr, memberName);//load handler method name il.Emit (OpCodes.Call, typeof(CompilerServices).GetMethod("getMethodInfoWithReflexion", BindingFlags.Static | BindingFlags.Public)); il.Emit (OpCodes.Stloc_0);//save MethodInfo il.Emit (OpCodes.Ldloc_0);//push mi for test if null @@ -795,8 +804,7 @@ namespace Crow int delDSIndex = cachedDelegates.Count; cachedDelegates.Add(dm.CreateDelegate (CompilerServices.ehTypeDSChange, this)); - ctx.emitCachedDelegateHandlerAddition(delDSIndex, typeof(GraphicObject).GetEvent("DataSourceChanged")); - return; + ctx.emitCachedDelegateHandlerAddition(delDSIndex, typeof(GraphicObject).GetEvent(bindOnEventName)); } }