Ejemplo n.º 1
0
            /// <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);
                }
            }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
            /// <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);
                }
            }
Ejemplo n.º 4
0
        /// <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);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Serialize the given node into an element.
 /// </summary>
 public abstract XElement Serialize(SerializationNode node, ISerializationNodeContainer parent);
Ejemplo n.º 6
0
 /// <summary>
 /// Can the given node be serialized?
 /// </summary>
 public abstract bool CanSerialize(SerializationNode node);
Ejemplo n.º 7
0
        /// <summary>
        /// Serialize the given node into an element.
        /// </summary>
        public XDocument Serialize(SerializationNode node)
        {
            var root = Serialize(node, null, null);

            return(new XDocument(root));
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Can the given node be serialized?
 /// </summary>
 public override bool CanSerialize(SerializationNode node)
 {
     return(node.GetType() == typeof(T));
 }