//if its a template, first read template elements
using (IMLReader reader = new IMLReader (il, tmpXml)) {
- string template = reader.GetAttribute ("Template");
+ string templatePath = reader.GetAttribute ("Template");
+ //string itemTemplatePath = reader.GetAttribute ("ItemTemplate");
bool inlineTemplate = false;
- if (string.IsNullOrEmpty (template)) {
- if (string.IsNullOrEmpty (templatePath)) {
-- reader.Read ();
--
-- while (reader.Read ()) {
-- if (!reader.IsStartElement ())
-- continue;
-- if (reader.Name == "Template") {
-- inlineTemplate = true;
-- reader.Read ();
--
-- readChildren (reader, crowType);
-- continue;
- }else if (reader.Name == "ItemTemplate") {
- } else if (reader.Name == "ItemTemplate") {
-- reader.Skip ();
- // string dataType = "default", datas = "", itemTmp;
- // while (reader.MoveToNextAttribute ()) {
- // if (reader.Name == "DataType")
- // dataType = reader.Value;
- // else if (reader.Name == "Data")
- // datas = reader.Value;
- // }
- //
- // reader.Read();
- // itemTmp = .ReadInnerXml ();
- //
- // if (ItemTemplates == null)
- // ItemTemplates = new Dictionary<string, ItemTemplate> ();
- // //TODO:check encoding
- // ItemTemplates[dataType] = new ItemTemplate (Encoding.UTF8.GetBytes(itemTmp));
- // if (!string.IsNullOrEmpty (datas))
- // ItemTemplates [dataType].CreateExpandDelegate(this, dataType, datas);
-
-- continue;
-
- string dataType = "default", datas = "", path = "";
- while (reader.MoveToNextAttribute ()) {
- if (reader.Name == "DataType")
- dataType = reader.Value;
- else if (reader.Name == "Data")
- datas = reader.Value;
- else if (reader.Name == "Path")
- path = reader.Value;
- }
-
- using (IMLReader iTmp = new IMLReader (null, reader.ReadInnerXml ())) {
- string uid = Guid.NewGuid ().ToString ();
- Interface.Instantiators [uid] =
- new ItemTemplate (iTmp.RootType, iTmp.GetLoader ());
- reader.il.Emit (OpCodes.Ldstr, dataType);
- reader.il.Emit (OpCodes.Ldstr, uid);
- reader.il.Emit (OpCodes.Callvirt,
- typeof(Interface).GetMethod ("GetItemTemplate"));
- reader.il.Emit (OpCodes.Callvirt,
- typeof(Dictionary<string, ItemTemplate>).GetMethod ("Add",
- new Type[] { typeof(string), typeof(ItemTemplate) }));
- }
-// if (!string.IsNullOrEmpty (datas))
-// ItemTemplates [dataType].CreateExpandDelegate(this, dataType, datas);
++ reader.Read ();
+
- continue;
++ while (reader.Read ()) {
++ if (!reader.IsStartElement ())
++ continue;
++ if (reader.Name == "Template") {
++ inlineTemplate = true;
++ reader.Read ();
++
++ readChildren (reader, crowType);
++ continue;
++ } else if (reader.Name == "ItemTemplate") {
++ string dataType = "default", datas = "", path = "";
++ while (reader.MoveToNextAttribute ()) {
++ if (reader.Name == "DataType")
++ dataType = reader.Value;
++ else if (reader.Name == "Data")
++ datas = reader.Value;
++ else if (reader.Name == "Path")
++ path = reader.Value;
}
- }
- if (!inlineTemplate) {
- DefaultTemplate dt = (DefaultTemplate)crowType.GetCustomAttributes (typeof(DefaultTemplate), true).FirstOrDefault();
- template = dt.Path;
+
- if (!inlineTemplate) {
- DefaultTemplate dt = (DefaultTemplate)crowType.GetCustomAttributes (typeof(DefaultTemplate), true).FirstOrDefault ();
- templatePath = dt.Path;
++ using (IMLReader iTmp = new IMLReader (null, reader.ReadInnerXml ())) {
++ string uid = Guid.NewGuid ().ToString ();
++ Interface.Instantiators [uid] =
++ new ItemTemplate (iTmp.RootType, iTmp.GetLoader ());
++ reader.il.Emit (OpCodes.Ldloc_0);//load TempControl ref
++ reader.il.Emit (OpCodes.Ldfld,//load ItemTemplates dic field
++ typeof(TemplatedControl).GetField("ItemTemplates"));
++ reader.il.Emit (OpCodes.Ldstr, dataType);//load key
++ reader.il.Emit (OpCodes.Ldstr, uid);//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) }));
+ }
++// if (!string.IsNullOrEmpty (datas))
++// ItemTemplates [dataType].CreateExpandDelegate(this, dataType, datas);
++
++ continue;
}
}
++
if (!inlineTemplate) {
-- reader.il.Emit (OpCodes.Ldloc_0);//Load this templateControl ref
++ if (string.IsNullOrEmpty (templatePath)) {
++ DefaultTemplate dt = (DefaultTemplate)crowType.GetCustomAttributes (typeof(DefaultTemplate), true).FirstOrDefault ();
++ if (dt!=null)
++ templatePath = dt.Path;
++ }
+
- reader.il.Emit (OpCodes.Ldstr, templatePath); //Load template path string
- reader.il.Emit (OpCodes.Callvirt,//call Interface.Load(path)
- typeof(Interface).GetMethod ("Load", BindingFlags.Static | BindingFlags.Public));
++ if (!string.IsNullOrEmpty (templatePath)) {
++ reader.il.Emit (OpCodes.Ldloc_0);//Load this templateControl ref
+
- reader.il.Emit (OpCodes.Ldstr, template); //Load template path string
- reader.il.Emit (OpCodes.Callvirt,//call Interface.Load(path)
- typeof(Interface).GetMethod ("Load", BindingFlags.Static | BindingFlags.Public));
++ reader.il.Emit (OpCodes.Ldstr, templatePath); //Load template path string
++ reader.il.Emit (OpCodes.Callvirt,//call Interface.Load(path)
++ typeof(Interface).GetMethod ("Load", BindingFlags.Static | BindingFlags.Public));
++ reader.il.Emit (OpCodes.Callvirt,//add child
++ crowType.GetMethod ("loadTemplate", BindingFlags.Instance | BindingFlags.NonPublic));
++ }
}
-- reader.il.Emit (OpCodes.Callvirt,//add child
-- crowType.GetMethod ("loadTemplate", BindingFlags.Instance | BindingFlags.NonPublic));
}
}
CompilerServices.EmitSetValue (reader.il, pi, style);
}
}
++ reader.il.Emit (OpCodes.Ldloc_0);
++ reader.il.Emit (OpCodes.Callvirt, typeof(GraphicObject).GetMethod ("loadDefaultValues"));
++
if (reader.HasAttributes) {
-- reader.il.Emit (OpCodes.Ldloc_0);
-- reader.il.Emit (OpCodes.Callvirt, typeof(GraphicObject).GetMethod ("loadDefaultValues"));
MethodInfo miAddBinding = typeof(GraphicObject).GetMethod ("BindMember");
miAddChild = typeof(Container).GetMethod ("SetChild");
else if (typeof(TemplatedContainer).IsAssignableFrom (crowType))
miAddChild = typeof(TemplatedContainer).GetProperty("Content").GetSetMethod();
++ else if (typeof(TemplatedControl).IsAssignableFrom (crowType))
++ miAddChild = typeof(TemplatedControl).GetMethod ("loadTemplate",
++ BindingFlags.Instance | BindingFlags.NonPublic);
else if (typeof(PrivateContainer).IsAssignableFrom (crowType))
miAddChild = typeof(PrivateContainer).GetMethod ("SetChild",
BindingFlags.Instance | BindingFlags.NonPublic);