From: jpbruyere Date: Tue, 9 Aug 2016 11:56:33 +0000 (+0200) Subject: binding emiting in Instanciator X-Git-Tag: v0.4~11^2~6 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=09069c1f3cd033c93fe2a5dbd97134155e35d877;p=jp%2Fcrow.git binding emiting in Instanciator modifié : src/CompilerServices/CompilerServices.cs remove CurrentInterface property for now from GraphicObject, some parentings are failing modifié : src/GraphicObjects/GraphicObject.cs --- diff --git a/src/CompilerServices/CompilerServices.cs b/src/CompilerServices/CompilerServices.cs index ebb365c9..80b4d535 100644 --- a/src/CompilerServices/CompilerServices.cs +++ b/src/CompilerServices/CompilerServices.cs @@ -12,6 +12,8 @@ namespace Crow { public static class CompilerServices { + static MethodInfo miAddBinding = typeof(GraphicObject).GetMethod ("BindMember"); + public static void BuildInstanciator(IMLInstantiatorBuilder builder, Type crowType){ string tmpXml = builder.ReadOuterXml (); @@ -52,6 +54,8 @@ namespace Crow reader.il.Emit (OpCodes.Callvirt,//add child typeof(PrivateContainer).GetMethod ("SetChild", BindingFlags.Instance | BindingFlags.NonPublic)); } + reader.il.Emit (OpCodes.Ldloc_0); + reader.il.Emit (OpCodes.Callvirt, crowType.GetMethod ("ResolveBindings")); } } @@ -69,18 +73,26 @@ namespace Crow reader.il.Emit (OpCodes.Ldloc_0); reader.il.Emit (OpCodes.Callvirt, typeof(GraphicObject).GetMethod ("loadDefaultValues")); + MethodInfo miAddBinding = typeof(GraphicObject).GetMethod ("BindMember"); + while (reader.MoveToNextAttribute ()) { if (reader.Name == "Style") continue; - PropertyInfo pi = crowType.GetProperty (reader.Name); - + MemberInfo mi = crowType.GetMember (reader.Name).FirstOrDefault(); + if (mi == null) + throw new Exception ("Member '" + reader.Name + "' not found in " + crowType.Name); + if (mi.MemberType == MemberTypes.Event) { + emitBindingCreation (reader.il, reader.Name, reader.Value); + continue; + } + PropertyInfo pi = mi as PropertyInfo; if (pi == null) throw new Exception ("Member '" + reader.Name + "' not found in " + crowType.Name); - if (reader.Value.StartsWith("{")) - Debug.WriteLine("Binding => " + pi.Name + ": " + reader.Value); - else + if (reader.Value.StartsWith ("{")) { + emitBindingCreation (reader.il, reader.Name, reader.Value.Substring (1, reader.Value.Length - 2)); + }else CompilerServices.EmitSetValue (reader.il, pi, reader.Value); } @@ -96,6 +108,12 @@ namespace Crow } builder.il.Emit (OpCodes.Pop);//pop saved ref to current object } + static void emitBindingCreation(ILGenerator il, string memberName, string expression){ + il.Emit (OpCodes.Ldloc_0); + il.Emit (OpCodes.Ldstr, memberName); + il.Emit (OpCodes.Ldstr, expression); + il.Emit (OpCodes.Callvirt, miAddBinding); + } static void readChildren(IMLInstantiatorBuilder reader, Type crowType){ MethodInfo miAddChild = null; bool endTagReached = false; diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 94e3f5e7..88166fe6 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -666,7 +666,7 @@ namespace Crow if (Width == Measure.Fit || Height == Measure.Fit) RegisterForLayouting (LayoutingType.Sizing); else if (RegisteredLayoutings == LayoutingType.None) - CurrentInterface.EnqueueForRepaint (this); + Interface.CurrentInterface.EnqueueForRepaint (this); } /// query an update of the content, a redraw [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -674,19 +674,19 @@ namespace Crow { bmp = null; if (RegisteredLayoutings == LayoutingType.None) - CurrentInterface.EnqueueForRepaint (this); - } - public Interface CurrentInterface { - get { - ILayoutable tmp = this.Parent; - while (tmp != null) { - if (tmp is Interface) - return tmp as Interface; - tmp = tmp.Parent; - } - return null; - } + Interface.CurrentInterface.EnqueueForRepaint (this); } +// public Interface CurrentInterface { +// get { +// ILayoutable tmp = this.Parent; +// while (tmp != null) { +// if (tmp is Interface) +// return tmp as Interface; +// tmp = tmp.Parent; +// } +// return null; +// } +// } #region Layouting