From 09069c1f3cd033c93fe2a5dbd97134155e35d877 Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Tue, 9 Aug 2016 13:56:33 +0200 Subject: [PATCH] =?utf8?q?binding=20emiting=20in=20Instanciator=20=09modif?= =?utf8?q?i=C3=A9=C2=A0:=20=20=20=20=20=20=20=20=20src/CompilerServices/Co?= =?utf8?q?mpilerServices.cs=20remove=20CurrentInterface=20property=20for?= =?utf8?q?=20now=20from=20GraphicObject,=20some=20parentings=20are=20faili?= =?utf8?q?ng=20=09modifi=C3=A9=C2=A0:=20=20=20=20=20=20=20=20=20src/Graphi?= =?utf8?q?cObjects/GraphicObject.cs?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/CompilerServices/CompilerServices.cs | 28 +++++++++++++++++++----- src/GraphicObjects/GraphicObject.cs | 26 +++++++++++----------- 2 files changed, 36 insertions(+), 18 deletions(-) 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 -- 2.47.3