public static ToolStripItemAbstract GetToolStripItemDevByXml(string strXml) { ToolStripItemAbstract toolStripItem = null; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(strXml); toolStripItem = (ToolStripItemAbstract)FormElementEntityDevTypes.Instance.CreateInstance(Convert.ToInt32(xmlDoc.SelectSingleNode("Element/ControlType").InnerText)); toolStripItem.FromXml(strXml); return(toolStripItem); }
/// <summary> /// 获取一个工具栏项实例(根据Id) /// </summary> /// <param name="id"></param> /// <returns></returns> public ToolStripItemAbstract GetEntity(string id) { XElement entityElement = (XElement)_cachingService.GetData(id); string strEntity; if (entityElement == null) { string file = Path.Combine(Constant.PACKAGE_NAVIGATION_TOOLSTRIP_FOLDER, id); bool fileExist = _packageService.Current.Container(file); Debug.Assert(fileExist, "工具栏项文件不存在"); if (fileExist == false) { return(null); } strEntity = _packageService.Current.GetFileContent(file); entityElement = XElement.Parse(strEntity); _cachingService.Add(id, entityElement); } else { strEntity = entityElement.ToString(); } int controlType = Convert.ToInt32(entityElement.Element("ControlType").Value); ToolStripItemAbstract entity = _toolStripItemEntityTypesFactory.CreateInstance(controlType); if (entity == null) { Debug.Assert(false, "_toolStripItemsContainer.Create(controlType) 失败,返回了null"); throw new Exception(); } entity.FromXml(strEntity); return(entity); }