/// <summary> /// Stor the value for this property into the XML. /// </summary> public void Store(XElement element, SerializationNode node) { var objectValue = property.GetValue(node); if ((!IsNull(objectValue)) && ((defaultValue == null) || !Equals(defaultValue, objectValue))) { var value = typeConverter.ConvertToString(objectValue); SetValue(element, value); } }
/// <summary> /// Serialize the given node into an element. /// </summary> public override XElement Serialize(SerializationNode node, ISerializationNodeContainer parent) { var element = new XElement(elementName); if (parent == null) { foreach (var attr in addNamespaces) { element.Add(new XAttribute(XNamespace.Xmlns + attr.Prefix, attr.Namespace)); } } properties.ForEach(x => x.Store(element, node)); return(element); }
/// <summary> /// Load the value for this property from the XML. /// </summary> public void Load(XElement element, SerializationNode node) { string value; if (TryGetValue(element, out value)) { var objectValue = typeConverter.ConvertFromString(value); property.SetValue(node, objectValue); } else if (defaultValue != null) { // Initialize to default value property.SetValue(node, defaultValue); } }
/// <summary> /// Serialize the given node into an element. /// </summary> private static XElement Serialize(SerializationNode node, ISerializationNodeContainer parentNode, XElement parent) { var element = Serializers.First(x => x.CanSerialize(node)).Serialize(node, parentNode); if (parent != null) { parent.Add(element); } var nodeAsContainer = node as ISerializationNodeContainer; if (nodeAsContainer != null) { foreach (var childNode in nodeAsContainer.Children) { Serialize(childNode, nodeAsContainer, element); } } return(element); }
/// <summary> /// Serialize the given node into an element. /// </summary> public abstract XElement Serialize(SerializationNode node, ISerializationNodeContainer parent);
/// <summary> /// Can the given node be serialized? /// </summary> public abstract bool CanSerialize(SerializationNode node);
/// <summary> /// Serialize the given node into an element. /// </summary> public XDocument Serialize(SerializationNode node) { var root = Serialize(node, null, null); return(new XDocument(root)); }
/// <summary> /// Can the given node be serialized? /// </summary> public override bool CanSerialize(SerializationNode node) { return(node.GetType() == typeof(T)); }