public XmlStream ToXmlStream() { XmlStream stream = new XmlStream(this.Name); Save(stream); return(stream); }
public PersistableClass(XmlStream stream) : this() { if (stream == null || stream.ParentNode == null || stream.ParentNode.Node == null) { return; } _nhi = stream.ParentNode.NumberFormat; FromNode(stream.ParentNode.Node); }
private void FromNode(XmlNode parent) { if (parent == null) { return; } _name = parent.Name; foreach (XmlNode node in parent.ChildNodes) { if (node.Attributes["type"] != null) { if (node.Attributes["type"].Value != "System.String") { Type type = global::System.Type.GetType(node.Attributes["type"].Value, false, true); object obj = Activator.CreateInstance(type); if (obj is XmlStreamObject) { XmlStream.ApplyXmlStreamObjectAttributes(node, (XmlStreamObject)obj); if (obj is XmlStreamOption) { List <object> options = new List <object>(); foreach (XmlNode optionNode in node.SelectNodes("Option[@type]")) { if (optionNode.Attributes["value"] == null) { continue; } Type optionType = global::System.Type.GetType(optionNode.Attributes["type"].Value, false, true); object optionObj = Convert.ChangeType(optionNode.Attributes["value"].Value, optionType, _nhi); options.Add(optionObj); } ((XmlStreamOption)obj).Options = options.ToArray(); XmlNode valueNode = node.SelectSingleNode("Value[@type]"); if (valueNode != null && valueNode.Attributes["value"] != null) { Type valueType = global::System.Type.GetType(valueNode.Attributes["type"].Value, false, true); object valueObj = Convert.ChangeType(valueNode.Attributes["value"].Value, valueType, _nhi); ((XmlStreamOption)obj).Value = valueObj; } else if (options.Count > 0) { ((XmlStreamOption)obj).Value = options[0]; } this.Add(new CustomProperty( node.Name, obj, ((XmlStreamObject)obj).Description, ((XmlStreamObject)obj).Category, ((XmlStreamOption)obj).Value.GetType(), ((XmlStreamObject)obj).IsReadOnly, true)); } else if (obj is XmlStreamStringArray) { List <object> values = new List <object>(); foreach (XmlNode valueNode in node.SelectNodes("Value[@type]")) { if (valueNode.Attributes["value"] == null) { continue; } Type valueType = global::System.Type.GetType(valueNode.Attributes["type"].Value, false, true); object valueObj = Convert.ChangeType(valueNode.Attributes["value"].Value, valueType, _nhi); values.Add(valueObj); } ((XmlStreamStringArray)obj).Value = values.ToArray(); this.Add(new CustomProperty( node.Name, obj, ((XmlStreamObject)obj).Description, ((XmlStreamObject)obj).Category, typeof(string[]), ((XmlStreamObject)obj).IsReadOnly, true)); } else { XmlNode valueNode = node.SelectSingleNode("Value[@type]"); if (valueNode != null && valueNode.Attributes["value"] != null) { Type valueType = global::System.Type.GetType(valueNode.Attributes["type"].Value, false, true); object valueObj = Convert.ChangeType(valueNode.Attributes["value"].Value, valueType, _nhi); ((XmlStreamObject)obj).Value = valueObj; } if (((XmlStreamObject)obj).Value != null) { this.Add(new CustomProperty( node.Name, obj, ((XmlStreamObject)obj).Description, ((XmlStreamObject)obj).Category, ((XmlStreamObject)obj).Value.GetType(), ((XmlStreamObject)obj).IsReadOnly, true)); } } continue; } if (node.Attributes["value"] != null) { obj = Convert.ChangeType(node.Attributes["value"].Value, type, _nhi); this.Add(new CustomProperty( node.Name, obj, "", "", type, false, false)); continue; } } else { if (node.Attributes["value"] != null) { Type type = typeof(global::System.String); string obj = String.Empty; obj = node.Attributes["value"].Value; this.Add(new CustomProperty( node.Name, obj, "", "", type, false, false)); continue; } } } _childClasses.Add(new PersistableClass(node, _nhi)); } }