private static Layout CreateLayoutFromRoot(XElement root) { string type = root.Attribute("type").Value; string[] parts = type.Split(':'); string fname = AppDomain.CurrentDomain.BaseDirectory + parts[0]; if (!File.Exists(fname)) { return(null); } Assembly assembly = Assembly.LoadFile(fname); if (assembly == null) { return(null); } object obj = assembly.CreateInstance(parts[1]); //无法创建只有带参数构造函数的对象 if (obj == null) { return(null); } IPersitable persitable = obj as IPersitable; persitable.InitByXml(root); return(persitable as Layout); }
private static void CreateInstanceFromElement(XElement node, IElement element) { if (node != null && node.Name != null && node.Name == "GeoGridLayer") { return; } string type = node.Attribute(XName.Get("type")).Value; string[] parts = type.Split(':'); string fname = AppDomain.CurrentDomain.BaseDirectory + parts[0]; if (!File.Exists(fname)) { return; } Assembly assembly = Assembly.LoadFile(fname); if (assembly == null) { return; } object obj = assembly.CreateInstance(parts[1]); IPersitable persitable = obj as IPersitable; persitable.InitByXml(node); IElementGroup group = element as IElementGroup; if (group != null) { group.Elements.Add(persitable as IElement); } //递归 IEnumerable <XElement> elements = node.Elements(); if (elements == null || elements.Count() == 0) { return; } foreach (XElement ele in elements) { CreateInstanceFromElement(ele, persitable as IElement); } return; }