protected override bool OnTryApply(UxDocument document)
        {
            if (!NodePath.TryFind(document, out UxElement node))
            {
                return(false);
            }

            var attr = node.Attributes.ElementAtOrDefault(AttributeIndex);

            if (attr == null || !attr.Syntax.Equals(OldAttribute))
            {
                return(false);
            }

            if (attr.Name == NewAttribute.Name.Text)
            {
                attr.ReplaceSyntax(NewAttribute);
            }
            else
            {
                if (!attr.Remove())
                {
                    return(false);
                }
                node.Attributes.Insert(AttributeIndex, new UxAttribute(NewAttribute));
            }
            return(true);
        }
Example #2
0
 public bool TryApply(UxDocument document)
 {
     if (document == null)
     {
         throw new ArgumentNullException(nameof(document));
     }
     return(OnTryApply(document));
 }
        public static void Merge(this UxDocument dst, UxDocument src)
        {
            if (dst == null)
            {
                throw new ArgumentNullException(nameof(dst));
            }
            if (src == null)
            {
                throw new ArgumentNullException(nameof(src));
            }

            MergeChildNodes(dst, src);
        }
Example #4
0
        protected override bool OnTryApply(UxDocument document)
        {
            if (!NodePath.TryFind(document, out UxElement node))
            {
                return(false);
            }

            if (!node.Syntax.Name.Equals(OldName))
            {
                return(false);
            }

            node.NameToken = NewName;

            return(true);
        }
Example #5
0
        protected override bool OnTryApply(UxDocument document)
        {
            if (!NodePath.TryFind(document, out UxNode node))
            {
                return(false);
            }

            if (!node.Syntax.Equals(OldNode))
            {
                return(false);
            }

            node.ReplaceWith(UxNode.FromSyntax(NewNode));

            return(true);
        }
Example #6
0
        protected override bool OnTryApply(UxDocument document)
        {
            UxElement node;

            if (!NodePath.TryFind(document, out node))
            {
                return(false);
            }

            if (node.Attributes.Count > AttributeIndex)
            {
                return(false);
            }

            node.Attributes.Insert(AttributeIndex, new UxAttribute(Attribute));
            return(true);
        }
Example #7
0
        public bool TryFind <TNode>(UxDocument document, out TNode node)
            where TNode : UxNode
        {
            // Hmm.. that / means root makes it hard to target other nodes
            // We could consider / meaning the document instead, and the root
            // being defined by /0 (if there's no comment nodes or trivia above or below)
            IUxContainer parent;

            if (TryFindPathParent(document, out parent))
            {
                var leafPos = _indexes.Last();
                node = parent.Nodes.ElementAtOrDefault(leafPos) as TNode;
                return(node != null);
            }
            node = null;
            return(false);
        }
Example #8
0
        protected override bool OnTryApply(UxDocument document)
        {
            UxElement node;

            if (!NodePath.TryFind(document, out node))
            {
                return(false);
            }

            var attr = node.Attributes.ElementAtOrDefault(AttributeIndex);

            if (attr == null || !attr.Syntax.Equals(Attribute))
            {
                return(false);
            }

            return(attr.Remove());
        }
Example #9
0
        protected override bool OnTryApply(UxDocument document)
        {
            IUxContainer parent;

            if (!NodePath.TryFindPathParent(document, out parent))
            {
                return(false);
            }

            var index = NodePath.Indexes.LastOrDefault();

            if (index > parent.Nodes.Count)
            {
                return(false);
            }

            parent.Nodes.Insert(index, UxNode.FromSyntax(Node));
            return(true);
        }
Example #10
0
        protected override bool OnTryApply(UxDocument document)
        {
            UxNode removed;

            if (!NodePath.TryFind(document, out removed))
            {
                return(false);
            }

            // We might want to loosen up the requirements for this to apply
            // To start with however we expect the removed node to be _exactly_
            // equal to Node.
            if (!removed.Syntax.Equals(Node))
            {
                return(false);
            }

            return(removed.Remove());
        }
Example #11
0
 public bool TryFindPathParent(UxDocument doc, out IUxContainer parent)
 {
     return(TryFindPathParent(doc, out parent, 0));
 }
 public static bool DeepEquals(this UxDocument a, UxDocument b)
 {
     return(a.Syntax.Equals(b.Syntax));
 }
Example #13
0
 protected abstract bool OnTryApply(UxDocument document);