Exemplo n.º 1
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);
        }
Exemplo n.º 2
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));
            }
            ;
        }