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

            DomNodeVisitor.Visit(obj, new OuterTextWriter(builder));
            return(builder.ToString());
        }
        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
                );
        }
Exemple #3
0
 public virtual int GetLineNumber(DomObject node)
 {
     if (node == null)
     {
         throw new ArgumentNullException(nameof(node));
     }
     return(-1);
 }
 public void Attaching(DomObject instance)
 {
     try {
         AttachingCore(instance);
     } finally {
         _node = instance;
     }
 }
 public void Detaching()
 {
     try {
         _observer.Dispose();
     } finally {
         _node = null;
     }
 }
Exemple #6
0
 public virtual void Dispatch(DomObject obj)
 {
     if (obj == null)
     {
         return;
     }
     SlowDispatch(obj);
 }
Exemple #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);
        }
Exemple #9
0
        bool IDomNodeCollection.Remove(DomObject node)
        {
            var attr = node as DomAttribute;

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

            if (!obj.IsAttribute)
            {
                VisitAll(((DomNode)obj).ChildNodes);
            }
        }
 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);
 }
Exemple #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;
            }
        }
 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);
 }
Exemple #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);
        }
Exemple #16
0
 void IDomObjectReferenceLifecycle.Attaching(DomObject instance)
 {
     Attaching((DomAttribute)instance);
 }
 public virtual void Attaching(DomObject instance)
 {
     _attachedDomObject = new WeakReference <DomObject>(instance);
 }
 void IDomNodeVisitDispatcher.Dispatch(DomObject obj)
 {
     _dispatcher.Dispatch(obj);
 }
 protected override void DefaultVisit(DomObject obj)
 {
     _visit(obj);
     base.DefaultVisit(obj);
 }
 public void Visit(DomObject obj)
 {
     ((IDomNodeVisitDispatcher)this).Dispatch(obj);
 }
Exemple #21
0
 public void Attaching(DomObject instance)
 {
     Lifecycle.Attaching(instance);
 }
Exemple #22
0
 void IDomObjectReferenceLifecycle.Attaching(DomObject instance)
 {
 }
        bool IDomNodeCollection.Remove(DomObject node)
        {
            var dn = node as DomNode;

            return(dn != null && Remove(dn));
        }
Exemple #24
0
 public bool Remove(DomObject item)
 {
     return(_list.Remove(item));
 }
Exemple #25
0
 public bool Contains(DomObject item)
 {
     return(_list.Contains(item));
 }
Exemple #26
0
 public void UnsafeAdd(DomObject item)
 {
     _list.Add(item);
 }
Exemple #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));
 }
Exemple #30
0
 internal void Track(DomObject item)
 {
     item.Link(_unlinked);
     _unlinked.UnsafeAdd(item);
 }