Ejemplo n.º 1
0
 void WriteContents(IEnumerable <object> items, XmlWriter w)
 {
     foreach (object o in XUtil.ExpandArray(items))
     {
         if (o == null)
         {
             continue;
         }
         else if (o is XStreamingElement)
         {
             ((XStreamingElement)o).WriteTo(w);
         }
         else if (o is XNode)
         {
             ((XNode)o).WriteTo(w);
         }
         else if (o is object [])
         {
             WriteContents((object [])o, w);
         }
         else if (o is XAttribute)
         {
             WriteAttribute((XAttribute)o, w);
         }
         else
         {
             new XText(o.ToString()).WriteTo(w);
         }
     }
 }
Ejemplo n.º 2
0
        public void AddAfterSelf(object content)
        {
            if (Owner == null)
            {
                throw new InvalidOperationException();
            }
            XNode here    = this;
            XNode orgNext = next;

            foreach (object o in XUtil.ExpandArray(content))
            {
                if (o == null || Owner.OnAddingObject(o, true, here, false))
                {
                    continue;
                }
                XNode n = XUtil.ToNode(o);
                Owner.OnAddingObject(n);
                n = (XNode)XUtil.GetDetachedObject(n);
                n.SetOwner(Owner);
                n.previous = here;
                here.next  = n;
                n.next     = orgNext;
                if (orgNext != null)
                {
                    orgNext.previous = n;
                }
                else
                {
                    Owner.LastNode = n;
                }
                here = n;
                Owner.OnAddedObject(n);
            }
        }
Ejemplo n.º 3
0
        public void AddBeforeSelf(object content)
        {
            if (Owner == null)
            {
                throw new InvalidOperationException();
            }
            foreach (object o in XUtil.ExpandArray(content))
            {
                if (o == null || Owner.OnAddingObject(o, true, previous, true))
                {
                    continue;
                }

                XNode n = XUtil.ToNode(o);
                Owner.OnAddingObject(n);
                n = (XNode)XUtil.GetDetachedObject(n);
                n.SetOwner(Owner);
                n.previous = previous;
                n.next     = this;
                if (previous != null)
                {
                    previous.next = n;
                }
                previous = n;
                if (Owner.FirstNode == this)
                {
                    Owner.FirstNode = n;
                }
                Owner.OnAddedObject(n);
            }
        }
Ejemplo n.º 4
0
 public void AddFirst(object content)
 {
     if (first == null)
     {
         Add(content);
     }
     else
     {
         first.AddBeforeSelf(XUtil.ExpandArray(content));
     }
 }
Ejemplo n.º 5
0
 public void Add(params object [] content)
 {
     if (content == null)
     {
         return;
     }
     foreach (object o in XUtil.ExpandArray(content))
     {
         Add(o);
     }
 }
Ejemplo n.º 6
0
        public void Add(object content)
        {
            if (content == null)
            {
                return;
            }

            foreach (object o in XUtil.ExpandArray(content))
            {
                if (!OnAddingObject(o, false, last, false))
                {
                    AddNode(XUtil.ToNode(o));
                }
            }
        }
Ejemplo n.º 7
0
 public void SetValue(object value)
 {
     if (value == null)
     {
         throw new ArgumentNullException("value");
     }
     if (value is XAttribute || value is XDocument || value is XDeclaration || value is XDocumentType)
     {
         throw new ArgumentException(String.Format("Node type {0} is not allowed as element value", value.GetType()));
     }
     RemoveNodes();
     foreach (object o in XUtil.ExpandArray(value))
     {
         Add(o);
     }
 }
Ejemplo n.º 8
0
		public void AddBeforeSelf (object content)
		{
			if (Parent == null)
				throw new InvalidOperationException ();
			foreach (object o in XUtil.ExpandArray (content)) {
				if (Owner.OnAddingObject (o, true, previous, true))
					continue;
				XNode n = XUtil.ToNode (o);
				n = (XNode) XUtil.GetDetachedObject (n);
				n.SetOwner (Parent);
				n.previous = previous;
				n.next = this;
				if (previous != null)
					previous.next = n;
				previous = n;
				if (Parent.FirstNode == this)
					Parent.FirstNode = n;
			}
		}
Ejemplo n.º 9
0
        public void ReplaceWith(object content)
        {
            if (Owner == null)
            {
                throw new InvalidOperationException();
            }

            XNode      here     = previous;
            XNode      orgNext  = next;
            XContainer orgOwner = Owner;

            Remove();
            foreach (object o in XUtil.ExpandArray(content))
            {
                if (o == null || orgOwner.OnAddingObject(o, true, here, false))
                {
                    continue;
                }
                XNode n = XUtil.ToNode(o);
                n = (XNode)XUtil.GetDetachedObject(n);
                n.SetOwner(orgOwner);
                n.previous = here;
                if (here != null)
                {
                    here.next = n;
                }
                else
                {
                    orgOwner.FirstNode = n;
                }
                n.next = orgNext;
                if (orgNext != null)
                {
                    orgNext.previous = n;
                }
                else
                {
                    orgOwner.LastNode = n;
                }
                here = n;
            }
        }
Ejemplo n.º 10
0
        public void ReplaceNodes(object content)
        {
            // First, it creates a snapshot copy, then removes the contents, and then adds the copy. http://msdn.microsoft.com/en-us/library/system.xml.linq.xcontainer.replacenodes.aspx

            if (FirstNode == null)
            {
                Add(content);
                return;
            }

            var l = new List <object> ();

            foreach (var obj in XUtil.ExpandArray(content))
            {
                l.Add(obj);
            }

            RemoveNodes();
            Add(l);
        }
Ejemplo n.º 11
0
 public void AddFirst(params object [] content)
 {
     if (content == null)
     {
         return;
     }
     if (first == null)
     {
         Add(content);
     }
     else
     {
         foreach (object o in XUtil.ExpandArray(content))
         {
             if (!OnAddingObject(o, false, first.PreviousNode, true))
             {
                 first.AddBeforeSelf(o);
             }
         }
     }
 }
Ejemplo n.º 12
0
        public void Add(object content)
        {
            if (content == null)
            {
                return;
            }

            foreach (object o in XUtil.ExpandArray(content))
            {
                if (o == null)
                {
                    continue;
                }

                if (!OnAddingObject(o, false, last, false))
                {
                    var node = XUtil.ToNode(o);
                    OnAddingObject(node);
                    AddNode(node);
                    OnAddedObject(node);
                }
            }
        }
Ejemplo n.º 13
0
 public void ReplaceAttributes(object content)
 {
     // it's waste of resource, but from bug #11298 it must save content
     // snapshot first and then remove existing attributes.
     ReplaceAttributes(XUtil.ExpandArray(content).ToArray());
 }