string templatePath = reader.GetAttribute ("Template");
//string itemTemplatePath = reader.GetAttribute ("ItemTemplate");
+ List<string[]> itemTemplateIds = new List<string[]> ();
bool inlineTemplate = false;
reader.Read ();
inlineTemplate = true;
reader.Read ();
- readChildren (reader, crowType);
+ readChildren (reader, crowType,true);
continue;
} else if (reader.Name == "ItemTemplate") {
string dataType = "default", datas = "", 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) }));
+ new ItemTemplate (iTmp.RootType, iTmp.GetLoader (), dataType, datas);
+
+ itemTemplateIds.Add (new string[] { dataType, uid, datas });
}
-// if (!string.IsNullOrEmpty (datas))
-// ItemTemplates [dataType].CreateExpandDelegate(this, dataType, datas);
continue;
}
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(TemplatedControl).GetField("ItemTemplates"));
+ 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) }));
+
+ 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(TemplatedControl).GetField ("ItemTemplates"));
+ 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.Ldloc_0);//load root of treeView
+ reader.il.Emit (OpCodes.Callvirt,
+ typeof(ItemTemplate).GetMethod ("CreateExpandDelegate"));
+ }
+ }
}
}
/// <summary>
/// Parse child node an generate corresponding msil
/// </summary>
- void readChildren(IMLReader reader, Type crowType){
+ void readChildren(IMLReader reader, Type crowType, bool templateLoading = false){
MethodInfo miAddChild = null;
bool endTagReached = false;
while (reader.Read()){
miAddChild = typeof(Group).GetMethod ("AddChild");
else if (typeof(Container).IsAssignableFrom (crowType))
miAddChild = typeof(Container).GetMethod ("SetChild");
- else if (typeof(TemplatedContainer).IsAssignableFrom (crowType))
+ else if (typeof(TemplatedContainer).IsAssignableFrom (crowType)&&!templateLoading)
miAddChild = typeof(TemplatedContainer).GetProperty("Content").GetSetMethod();
else if (typeof(TemplatedControl).IsAssignableFrom (crowType))
miAddChild = typeof(TemplatedControl).GetMethod ("loadTemplate",
{
public class ItemTemplate : Instantiator {
public EventHandler Expand;
+ string strDataType;
+ string fetchMethodName;
#region CTOR
public ItemTemplate(string path)
: base(path) {
}
- public ItemTemplate (Type _root, Interface.LoaderInvoker _loader)
+ public ItemTemplate (Type _root, Interface.LoaderInvoker _loader,string _dataType, string _fetchDataMethod)
:base(_root, _loader)
{
+ strDataType = _dataType;
+ fetchMethodName = _fetchDataMethod;
}
#endregion
- public void CreateExpandDelegate (TemplatedControl host, string strDataType, string method){
+ public void CreateExpandDelegate (TemplatedControl host){
Type dataType = Type.GetType(strDataType);
Type hostType = typeof(TemplatedControl);//not sure is the best place to put the dyn method
Type evtType = typeof(EventHandler);
Type handlerArgsType = evtParams [1].ParameterType;
Type [] args = { typeof (object), typeof (object), handlerArgsType };
- DynamicMethod dm = new DynamicMethod ("dyn_expand_" + method,
+ DynamicMethod dm = new DynamicMethod ("dyn_expand_" + fetchMethodName,
typeof (void),
args,
hostType);
il.Emit (OpCodes.Ldarg_1);
il.Emit (OpCodes.Callvirt, typeof(GraphicObject).GetProperty("DataSource").GetGetMethod ());
- MethodInfo miGetDatas = dataType.GetMethod (method, new Type[] {});
+ MethodInfo miGetDatas = dataType.GetMethod (fetchMethodName, new Type[] {});
il.Emit (OpCodes.Callvirt, miGetDatas);
il.Emit (OpCodes.Callvirt, listBoxType.GetProperty("Data").GetSetMethod ());