private void ProcessMemento(IMemento memento, XmlNode xmlnode) { //1.循环获取属性信息 XmlAttributeCollection xmlAttributes = xmlnode.Attributes; IEnumerator attrEnumerator = xmlAttributes.GetEnumerator(); while (attrEnumerator.MoveNext()) { XmlAttribute xmlAttribute = (XmlAttribute)attrEnumerator.Current; if (!String.IsNullOrEmpty(xmlAttribute.Value)) { memento.SetString(xmlAttribute.Name, xmlAttribute.Value); } } //2.递归进行ChildMemento处理,需要创建ChildMemento对象 XmlNodeList childrenNodes = xmlnode.ChildNodes; IEnumerator nodeEnumerator = childrenNodes.GetEnumerator(); while (nodeEnumerator.MoveNext()) { XmlNode childNode = (XmlNode)nodeEnumerator.Current; if (childNode.NodeType != XmlNodeType.Comment) { IMemento childMemento = memento.CreateChild(childNode.Name); ProcessMemento(childMemento, childNode); } } }
public override void SaveState(IMemento memento) { memento.Name = "StockMarkInfoMananger"; memento.SetString("Version", _CurrentVersion); if (_StockMarkInfo != null) { foreach (int code in _StockMarkInfo.Keys) { IMemento childMemento = memento.CreateChild("StockMarkInfo"); _StockMarkInfo[code].SaveState(childMemento); } } }