Example #1
0
        private Label CreateLabelFromNode(LabelXmlNode xmlNode)
        {
            var element = (Label)SimpleObjectMapper.MapFlat(xmlNode, typeof(Label));

            foreach (LabelContentXmlNode node in xmlNode.Content)
            {
                var nodeType = node.GetType();
                var o        = (ILabelContent)SimpleObjectMapper.MapFlat(node, MappingTable.XmlToElementType(nodeType));
                element.Content.Add(o);
            }

            return(element);
        }
        public ElementNodeList(IEnumerable <ILabelContent> source)
        {
            foreach (var obj in source)
            {
                var objType = obj.GetType();

                var map = MappingTable.Find(objType);

                if (map == null)
                {
                    throw new InvalidOperationException("Not supported mapping type.");
                }

                Add((LabelContentXmlNode)SimpleObjectMapper.MapFlat(obj, map.XmlNodeType));
            }
            ;
        }
        public void ReadXml(XmlReader reader)
        {
            var nodes = XElement.Parse(reader.ReadOuterXml()).Elements().ToList();

            foreach (var node in nodes)
            {
                var map = MappingTable.Find(node.Name.LocalName);

                if (map == null)
                {
                    throw new InvalidOperationException("Not supported mapping type.");
                }

                var serializer = new XmlSerializer(map.XmlNodeType);

                using (var nodeReader = node.CreateReader())
                    Add((LabelContentXmlNode)serializer.Deserialize(nodeReader));
            }
        }
Example #4
0
        public void Serialize(Stream stream, ILabel label, bool serializeDefaults = false)
        {
            if (label == null)
            {
                throw new ArgumentNullException(nameof(label));
            }

            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            var labelXmlNode = (LabelXmlNode)SimpleObjectMapper.MapFlat(label, typeof(LabelXmlNode));

            (labelXmlNode as IDefaultSerializable).SerializeDefaults = serializeDefaults;
            labelXmlNode.Version = VersionProvider.ProductVersion;

            foreach (LabelContent element in label.Content)
            {
                LabelContentXmlNode node = (LabelContentXmlNode)SimpleObjectMapper.MapFlat(element, MappingTable.ElementToXmlType(element.GetType()));
                (node as IDefaultSerializable).SerializeDefaults = serializeDefaults;
                labelXmlNode.Content.Add(node);
            }

            serializer.Serialize(stream, labelXmlNode);
        }