Exemple #1
0
        public void Add(object content)
        {
            if (content == null)
            {
                return;
            }

            foreach (object o in XUtil.ExpandArray(content))
            {
                if (!OnAddingObject(o, false, last, false))
                {
                    OnAddingObject();
                    AddNode(XUtil.ToNode(o));
                    OnAddedObject();
                }
            }
        }
 void SetAttributeObject(XAttribute a)
 {
     OnAddingObject(a);
     a = (XAttribute)XUtil.GetDetachedObject(a);
     a.SetOwner(this);
     if (attr_first == null)
     {
         attr_first = a;
         attr_last  = a;
     }
     else
     {
         attr_last.NextAttribute = a;
         a.PreviousAttribute     = attr_last;
         attr_last = a;
     }
     OnAddedObject(a);
 }
Exemple #3
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;
			}
		}
Exemple #4
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;
            }
        }
Exemple #5
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);
        }
Exemple #6
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);
             }
         }
     }
 }
Exemple #7
0
		public void AddAfterSelf (object content)
		{
			if (Parent == null)
				throw new InvalidOperationException ();
			XNode here = this;
			XNode orgNext = next;
			foreach (object o in XUtil.ExpandArray (content)) {
				if (Owner.OnAddingObject (o, true, here, false))
					continue;
				XNode n = XUtil.ToNode (o);
				n = (XNode) XUtil.GetDetachedObject (n);
				n.SetOwner (Parent);
				n.previous = here;
				here.next = n;
				n.next = orgNext;
				if (orgNext != null)
					orgNext.previous = n;
				else
					Parent.LastNode = n;
				here = n;
			}
		}
        public void SetAttributeValue(XName name, object value)
        {
            XAttribute a = Attribute(name);

            if (value == null)
            {
                if (a != null)
                {
                    a.Remove();
                }
            }
            else
            {
                if (a == null)
                {
                    SetAttributeObject(new XAttribute(name, value));
                }
                else
                {
                    a.Value = XUtil.ToString(value);
                }
            }
        }
Exemple #9
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);
                }
            }
        }
 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());
 }