]> O.S.I.I.S - jp/crow.git/commitdiff
move recurent reflexion to static in CompilerServices
authorjpbruyere <jp.bruyere@hotmail.com>
Tue, 13 Sep 2016 16:37:42 +0000 (18:37 +0200)
committerjpbruyere <jp.bruyere@hotmail.com>
Tue, 13 Sep 2016 16:37:42 +0000 (18:37 +0200)
modifié :         src/CompilerServices/CompilerServices.cs
modifié :         src/IMLReader.cs

src/CompilerServices/CompilerServices.cs
src/IMLReader.cs

index 43c9d7048dfd004adbb92093a4c7f98e44f1b0b8..48f95a8a17be49b5656763d85305838a6840ffa0 100644 (file)
@@ -18,7 +18,15 @@ namespace Crow
                static MethodInfo stringEquals = typeof (string).GetMethod
                        ("Equals", new Type [3] { typeof (string), typeof (string), typeof (StringComparison) });
                static MethodInfo miFindByName = typeof (GraphicObject).GetMethod ("FindByName");
-               
+
+               public static MethodInfo miIFaceLoad = typeof(Interface).GetMethod ("Load", BindingFlags.Instance | BindingFlags.Public);
+               public static MethodInfo miGetITemp = typeof(Interface).GetMethod ("GetItemTemplate");
+               public static MethodInfo miAddITemp = typeof(Dictionary<string, ItemTemplate>).
+                       GetMethod ("set_Item", new Type[] { typeof(string), typeof(ItemTemplate) });
+               public static MethodInfo miGetITempFromDic = typeof(Dictionary<string, ItemTemplate>).
+                       GetMethod ("get_Item", new Type[] { typeof(string) });
+               public static FieldInfo fldItemTemplates = typeof(TemplatedGroup).GetField("ItemTemplates");
+               public static MethodInfo miCreateExpDel = typeof(ItemTemplate).GetMethod ("CreateExpandDelegate");
 
                #region ValueChange Reflexion member info
                static EventInfo eiValueChange = typeof (IValueChange).GetEvent ("ValueChanged");
index ad4fd835927ec7f1c3f5b289eff8ba23d3d422ad..1fae7a22f2e882f295f383f18da8e0a518d9aa9f 100644 (file)
@@ -120,7 +120,7 @@ namespace Crow
                                                        inlineTemplate = true;
                                                        reader.Read ();
 
-                                                       readChildren (reader, crowType,true);
+                                                       readChildren (reader, crowType, true);
                                                } else if (reader.Name == "ItemTemplate") {
                                                        string dataType = "default", datas = "", path = "";
                                                        while (reader.MoveToNextAttribute ()) {
@@ -160,35 +160,27 @@ namespace Crow
                                                        reader.il.Emit (OpCodes.Ldarg_1);//load currentInterface
                                                        reader.il.Emit (OpCodes.Ldstr, templatePath); //Load template path string
                                                        reader.il.Emit (OpCodes.Callvirt,//call Interface.Load(path)
-                                                                       typeof(Interface).GetMethod ("Load", BindingFlags.Instance | BindingFlags.Public));
+                                                               CompilerServices.miIFaceLoad);
                                                }
                                                reader.il.Emit (OpCodes.Callvirt,//load template
                                                        crowType.GetMethod ("loadTemplate", BindingFlags.Instance | BindingFlags.NonPublic));
                                        }
                                        foreach (string[] iTempId in itemTemplateIds) {
                                                reader.il.Emit (OpCodes.Ldloc_0);//load TempControl ref
-                                               reader.il.Emit (OpCodes.Ldfld,//load ItemTemplates dic field
-                                                       typeof(TemplatedGroup).GetField("ItemTemplates"));
+                                               reader.il.Emit (OpCodes.Ldfld, CompilerServices.fldItemTemplates);//load ItemTemplates dic field
                                                reader.il.Emit (OpCodes.Ldstr, iTempId[0]);//load key
                                                reader.il.Emit (OpCodes.Ldstr, iTempId[1]);//load value
-                                               reader.il.Emit (OpCodes.Callvirt,
-                                                       typeof(Interface).GetMethod ("GetItemTemplate"));
-                                               reader.il.Emit (OpCodes.Callvirt,
-                                                       typeof(Dictionary<string, ItemTemplate>).GetMethod ("set_Item",
-                                                               new Type[] { typeof(string), typeof(ItemTemplate) }));
+                                               reader.il.Emit (OpCodes.Callvirt, CompilerServices.miGetITemp);
+                                               reader.il.Emit (OpCodes.Callvirt, CompilerServices.miAddITemp);
 
                                                if (!string.IsNullOrEmpty (iTempId [2])) {
                                                        //expand delegate creation
                                                        reader.il.Emit (OpCodes.Ldloc_0);//load TempControl ref
-                                                       reader.il.Emit (OpCodes.Ldfld,//load ItemTemplates dic field
-                                                               typeof(TemplatedGroup).GetField ("ItemTemplates"));
+                                                       reader.il.Emit (OpCodes.Ldfld, CompilerServices.fldItemTemplates);
                                                        reader.il.Emit (OpCodes.Ldstr, iTempId [0]);//load key
-                                                       reader.il.Emit (OpCodes.Callvirt,
-                                                               typeof(Dictionary<string, ItemTemplate>).GetMethod ("get_Item",
-                                                                       new Type[] { typeof(string) }));
+                                                       reader.il.Emit (OpCodes.Callvirt, CompilerServices.miGetITempFromDic);
                                                        reader.il.Emit (OpCodes.Ldloc_0);//load root of treeView
-                                                       reader.il.Emit (OpCodes.Callvirt,
-                                                               typeof(ItemTemplate).GetMethod ("CreateExpandDelegate"));
+                                                       reader.il.Emit (OpCodes.Callvirt, CompilerServices.miCreateExpDel);
                                                }
                                        }
                                }
@@ -305,8 +297,6 @@ namespace Crow
                                        reader.emitLoader (t);
 
                                        reader.il.Emit (OpCodes.Ldloc_0);//load child on stack for parenting
-                                       if (miAddChild == null)
-                                               System.Diagnostics.Debugger.Break ();
                                        reader.il.Emit (OpCodes.Callvirt, miAddChild);
                                        reader.il.Emit (OpCodes.Stloc_0); //reset local to current go
                                        reader.il.Emit (OpCodes.Ldloc_0);//save current go onto the stack if child has to be added