From 09069c1f3cd033c93fe2a5dbd97134155e35d877 Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Tue, 9 Aug 2016 13:56:33 +0200 Subject: 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 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/CompilerServices/CompilerServices.cs | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'src/CompilerServices/CompilerServices.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; -- cgit v1.3.1-4-g156e