Example #1
0
        public static string ConvertToString(DomObject obj)
        {
            var builder = new StringBuilder();

            DomNodeVisitor.Visit(obj, new OuterTextWriter(builder));
            return(builder.ToString());
        }
Example #2
0
        private void AttachingCore(DomObject instance)
        {
            if (!(instance is DomContainer))
            {
                return;
            }

            var doc = (instance is DomDocument dd) ? dd : instance.OwnerDocument;

            // Special case: monitor the document node to add it to the document element
            // if the document element is later added
            DomObserver docElement = null;

            if (instance is DomDocument document)
            {
                docElement = doc.ObserveChildNodes((DomNode)instance, AddNamespaceToDocumentElement, DomScope.Target);
                if (document.DocumentElement != null)
                {
                    document.DocumentElement.NameContext = new XmlNameContext();
                }
            }

            _observer = DomObserver.Compose(
                doc.ObserveAttributes((DomNode)instance, FixupNamespace, DomScope.TargetAndDescendants),
                docElement
                );
        }
Example #3
0
 public virtual int GetLineNumber(DomObject node)
 {
     if (node == null)
     {
         throw new ArgumentNullException(nameof(node));
     }
     return(-1);
 }
Example #4
0
 public void Attaching(DomObject instance)
 {
     try {
         AttachingCore(instance);
     } finally {
         _node = instance;
     }
 }
Example #5
0
 public void Detaching()
 {
     try {
         _observer.Dispose();
     } finally {
         _node = null;
     }
 }
Example #6
0
 public virtual void Dispatch(DomObject obj)
 {
     if (obj == null)
     {
         return;
     }
     SlowDispatch(obj);
 }
Example #7
0
        public void Write(DomObject obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }

            DomNodeVisitor.Visit(obj, this);
        }
        int IDomNodeCollection.GetSiblingIndex(DomObject node)
        {
            var dn = node as DomNode;

            if (dn != null)
            {
                return(IndexOf(dn));
            }
            return(-1);
        }
Example #9
0
        bool IDomNodeCollection.Remove(DomObject node)
        {
            var attr = node as DomAttribute;

            if (attr != null && _items.Remove(attr))
            {
                return(true);
            }
            return(false);
        }
Example #10
0
        protected virtual void DefaultVisit(DomObject obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }

            if (!obj.IsAttribute)
            {
                VisitAll(((DomNode)obj).ChildNodes);
            }
        }
Example #11
0
 public static void Visit(DomObject obj, Action <DomObject> visitor)
 {
     if (obj == null)
     {
         throw new ArgumentNullException(nameof(obj));
     }
     if (visitor == null)
     {
         throw new ArgumentNullException(nameof(visitor));
     }
     new ThunkVisitor(visitor).Visit(obj);
 }
Example #12
0
        private static void FastDispatch(IDomNodeVisitor v, DomObject obj)
        {
            switch (obj)
            {
            case DomElement _:
                v.Visit((DomElement)obj);
                return;

            case DomAttribute _:
                v.Visit((DomAttribute)obj);
                return;

            case DomText _:
                v.Visit((DomText)obj);
                return;

            case DomCDataSection _:
                v.Visit((DomCDataSection)obj);
                return;

            case DomEntityReference _:
                v.Visit((DomEntityReference)obj);
                return;

            case DomEntity _:
                v.Visit((DomEntity)obj);
                return;

            case DomProcessingInstruction _:
                v.Visit((DomProcessingInstruction)obj);
                return;

            case DomComment _:
                v.Visit((DomComment)obj);
                return;

            case DomDocument _:
                v.Visit((DomDocument)obj);
                return;

            case DomDocumentType _:
                v.Visit((DomDocumentType)obj);
                return;

            case DomDocumentFragment _:
                v.Visit((DomDocumentFragment)obj);
                return;

            case DomNotation _:
                v.Visit((DomNotation)obj);
                return;
            }
        }
Example #13
0
 public static void Visit(DomObject obj, IDomNodeVisitor visitor)
 {
     if (obj == null)
     {
         throw new ArgumentNullException(nameof(obj));
     }
     if (visitor == null)
     {
         throw new ArgumentNullException(nameof(visitor));
     }
     DomNodeVisitDispatcher.Create(visitor).Dispatch(obj);
 }
Example #14
0
        private void SlowDispatch(DomObject obj)
        {
            var type = obj.GetType();

            while (!CanFastDispatch(type))
            {
                if (DispatchCache.TryGetValue(type, out MethodInfo method))
                {
                    method.InvokeWithUnwrap(_visitor, new[] { obj });
                    return;
                }
                type = type.BaseType;
            }

            FastDispatch(_visitor, obj);
        }
        public DomNode Append(DomObject child)
        {
            if (child == null)
            {
                return(this);
            }

            if (child.NodeType == DomNodeType.Attribute)
            {
                Attributes.Add((DomAttribute)child);
            }
            else
            {
                Append((DomNode)child);
            }

            return(this);
        }
Example #16
0
 void IDomObjectReferenceLifecycle.Attaching(DomObject instance)
 {
     Attaching((DomAttribute)instance);
 }
 public virtual void Attaching(DomObject instance)
 {
     _attachedDomObject = new WeakReference <DomObject>(instance);
 }
Example #18
0
 void IDomNodeVisitDispatcher.Dispatch(DomObject obj)
 {
     _dispatcher.Dispatch(obj);
 }
Example #19
0
 protected override void DefaultVisit(DomObject obj)
 {
     _visit(obj);
     base.DefaultVisit(obj);
 }
Example #20
0
 public void Visit(DomObject obj)
 {
     ((IDomNodeVisitDispatcher)this).Dispatch(obj);
 }
Example #21
0
 public void Attaching(DomObject instance)
 {
     Lifecycle.Attaching(instance);
 }
Example #22
0
 void IDomObjectReferenceLifecycle.Attaching(DomObject instance)
 {
 }
        bool IDomNodeCollection.Remove(DomObject node)
        {
            var dn = node as DomNode;

            return(dn != null && Remove(dn));
        }
Example #24
0
 public bool Remove(DomObject item)
 {
     return(_list.Remove(item));
 }
Example #25
0
 public bool Contains(DomObject item)
 {
     return(_list.Contains(item));
 }
Example #26
0
 public void UnsafeAdd(DomObject item)
 {
     _list.Add(item);
 }
Example #27
0
 public int GetSiblingIndex(DomObject item)
 {
     return(-1);
 }
 protected virtual DomNameContext CreateDomNameContext(DomObject owner)
 {
     return(DomNameContext.Xml);
 }
 public DomNameContext CreateNameContext(DomObject owner)
 {
     return(CreateDomNameContext(owner));
 }
Example #30
0
 internal void Track(DomObject item)
 {
     item.Link(_unlinked);
     _unlinked.UnsafeAdd(item);
 }