Example #1
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
                );
        }
            public ElementsByAttributeIndex(DomDocument owner, DomName name, Func <string, TKey> func, IEqualityComparer <TKey> comparer) : base(comparer)
            {
                _attributeName = name;
                _func          = func;
                _observer      = DomObserver.Compose(
                    owner.ObserveAttributes(name, Handler),
                    owner.ObserveChildNodes(Handler)
                    );

                foreach (var desc in owner.DescendantsAndSelf)
                {
                    Add(desc.Attribute(_attributeName), desc);
                }
            }
Example #3
0
        public DomObserver ObserveChildNodes(DomNode target, Action <DomMutationEvent> handler, DomScope scope)
        {
            if (target is null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            if (handler is null)
            {
                throw new ArgumentNullException(nameof(handler));
            }

            var result = DomObserver.ChildNodes(handler);

            _observers.RegisterObserver(
                result, target, scope, DomObserverEventScope.ChildNodes
                );
            return(result);
        }
Example #4
0
        public DomObserver ObserveAttributes(DomNode target, DomName attribute, Action <DomAttributeEvent> handler, DomScope scope)
        {
            if (target is null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            if (attribute is null)
            {
                throw new ArgumentNullException(nameof(attribute));
            }
            if (handler is null)
            {
                throw new ArgumentNullException(nameof(handler));
            }

            var result = DomObserver.Attributes(handler);

            _observers.RegisterObserver(
                result, target, scope, DomObserverEventScope.AnyAttribute
                );
            return(result);
        }
Example #5
0
        public void RegisterObserver(DomObserver observer, DomNode target, DomScope scope, DomObserverEventScope events)
        {
            var list = GetItemsForScope(events);

            list.Add(new ScopedDomObserverTarget(observer, target, scope));
        }
Example #6
0
 public ScopedDomObserverTarget(DomObserver observer, DomNode target, DomScope scope) : base(observer)
 {
     Target = target;
     Scope  = scope;
 }