コード例 #1
0
        protected override void Serialize(object target, XmlElementContext context)
        {
            _listBuilder?.Begin(GetValue(target), true);

            var content        = _listBuilder?.Objects;
            var targetElements = XmlElementSerializer
                                 .GetElements(context.XElement, true, _rootTarget, content?.Length ?? 0)?.ToArray();

            if (targetElements == null)
            {
                throw new InvalidOperationException("Serialize No Data Returned");
            }

            if (content == null)
            {
                return;
            }

            for (var i = 0; i < content.Length; i++)
            {
                _serializer.Serialize(content[i], targetElements[i]);
            }

            _listBuilder?.End();
        }
コード例 #2
0
        private IEnumerable <XElement>?GetElements(bool forWrite, [NotNull] XElement context, int count)
        {
            var realRoot = XmlElementSerializer.GetElement(context, forWrite, _rootTarget) as XElement;

            if (realRoot == null && forWrite)
            {
                throw new InvalidOperationException("Attributes not Supported");
            }

            return(realRoot == null
                ? Enumerable.Empty <XElement>()
                : XmlElementSerializer.GetElements(realRoot, forWrite, _target, count));
        }
コード例 #3
0
        protected override void Deserialize(object target, XmlElementContext context)
        {
            _listBuilder?.Begin(null, false);

            var targetElements = XmlElementSerializer.GetElements(context.XElement, false, _rootTarget, -1)?.ToArray();

            if (targetElements == null)
            {
                return;
            }

            foreach (var targetElement in targetElements)
            {
                _listBuilder?.Add(_serializer.Deserialize(targetElement));
            }

            SetValue(target, _listBuilder?.End());
        }