Пример #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);
                }
            }
Пример #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);
        }
Пример #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);
                }
            }
Пример #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);
        }
Пример #5
0
 /// <summary>
 /// Serialize the given node into an element.
 /// </summary>
 public abstract XElement Serialize(SerializationNode node, ISerializationNodeContainer parent);
Пример #6
0
 /// <summary>
 /// Can the given node be serialized?
 /// </summary>
 public abstract bool CanSerialize(SerializationNode node);
Пример #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));
        }
Пример #8
0
 /// <summary>
 /// Can the given node be serialized?
 /// </summary>
 public override bool CanSerialize(SerializationNode node)
 {
     return(node.GetType() == typeof(T));
 }