Esempio n. 1
0
        public static string ConvertToString(DomObject obj)
        {
            var builder = new StringBuilder();

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

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

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

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