예제 #1
0
 public ForeachNode(ForeachNode original)
     : base(original)
 {
     this.ValueProvider   = original.ValueProvider;
     this.ForeachToken    = original.ForeachToken.CloneNode();
     this.EndForeachToken = original.EndForeachToken.CloneNode();
     this.ForeachBlock    = (BlockNode?)original.ForeachBlock?.Let(a => a.CloneNode(true));
 }
예제 #2
0
        public OpenXmlElement CommonParent(MatchNodePair other)
        {
            if (this.AscendantNode.Parent != other.AscendantNode.Parent)
            {
                throw new InvalidOperationException("Parents do not match");
            }

            return(this.AscendantNode.Parent);
        }
예제 #3
0
        public AnyNode(AnyNode original)
            : base(original)
        {
            this.ValueProvider = original.ValueProvider;
            this.Operation     = original.Operation;
            this.Value         = original.Value;

            this.AnyToken    = original.AnyToken.CloneNode();
            this.NotAnyToken = original.NotAnyToken.CloneNode();
            this.EndAnyToken = original.EndAnyToken.CloneNode();

            this.AnyBlock    = (BlockNode)original.AnyBlock?.Let(a => a.CloneNode(true));
            this.NotAnyBlock = (BlockNode)original.NotAnyBlock?.Let(a => a.CloneNode(true));
        }
예제 #4
0
        public IfNode(IfNode original)
            : base(original)
        {
            this.ValueProvider = original.ValueProvider;
            this.Operation     = original.Operation;
            this.Value         = original.Value;

            this.IfToken    = original.IfToken.CloneNode();
            this.ElseToken  = original.ElseToken.CloneNode();
            this.EndIfToken = original.EndIfToken.CloneNode();

            this.IfBlock   = (BlockNode)original.IfBlock?.Let(a => a.CloneNode(true));
            this.ElseBlock = (BlockNode)original.ElseBlock?.Let(a => a.CloneNode(true));
        }
예제 #5
0
        protected void NormalizeInterval(ref MatchNodePair first, ref MatchNodePair last, MatchNode errorHintParent)
        {
            if (first.MatchNode == last.MatchNode)
            {
                throw new ArgumentException("first and last are the same node");
            }

            var chainFirst = ((OpenXmlElement)first.MatchNode).Follow(a => a.Parent).Reverse().ToList();
            var chainLast  = ((OpenXmlElement)last.MatchNode).Follow(a => a.Parent).Reverse().ToList();

            var result = chainFirst.Zip(chainLast, (f, l) => new { f, l }).First(a => a.f != a.l);

            AssertNotImportant(chainFirst, result.f !, errorHintParent, first.MatchNode, last.MatchNode); /*CSBUG*/
            AssertNotImportant(chainLast, result.l !, errorHintParent, last.MatchNode, first.MatchNode);

            first.AscendantNode = result.f !;
            last.AscendantNode  = result.l !;
        }
예제 #6
0
        protected static List <OpenXmlElement> NodesBetween(MatchNodePair first, MatchNodePair last)
        {
            var parent = first.CommonParent(last);

            int indexFirst = parent.ChildElements.IndexOf(first.AscendantNode);

            if (indexFirst == -1)
            {
                throw new InvalidOperationException("Element not found");
            }

            int indexLast = parent.ChildElements.IndexOf(last.AscendantNode);

            if (indexLast == -1)
            {
                throw new InvalidOperationException("Element not found");
            }

            var childs = parent.ChildElements.Where((e, i) => indexFirst < i && i < indexLast).ToList();

            return(childs);
        }
        public IfNode(IfNode original)
            : base(original)
        {
            this.ValueProvider = original.ValueProvider;
            this.Operation = original.Operation;
            this.Value = original.Value;

            this.IfToken = original.IfToken.CloneNode();
            this.ElseToken = original.ElseToken.CloneNode();
            this.EndIfToken = original.EndIfToken.CloneNode();

            this.IfBlock = (BlockNode)original.IfBlock.Try(a => a.CloneNode(true));
            this.ElseBlock = (BlockNode)original.ElseBlock.Try(a => a.CloneNode(true));
        }
        public AnyNode(AnyNode original)
            : base(original)
        {
            this.ValueProvider = original.ValueProvider;
            this.Operation = original.Operation;
            this.Value = original.Value;

            this.AnyToken = original.AnyToken.CloneNode();
            this.NotAnyToken = original.NotAnyToken.CloneNode();
            this.EndAnyToken = original.EndAnyToken.CloneNode();

            this.AnyBlock = (BlockNode)original.AnyBlock.Try(a => a.CloneNode(true));
            this.NotAnyBlock = (BlockNode)original.NotAnyBlock.Try(a => a.CloneNode(true));
        }
        public OpenXmlElement CommonParent(MatchNodePair other)
        {
            if (this.AscendantNode.Parent != other.AscendantNode.Parent)
                throw new InvalidOperationException("Parents do not match");

            return this.AscendantNode.Parent;
        }
 public ForeachNode(ForeachNode original)
     : base(original)
 {
     this.ValueProvider = original.ValueProvider;
     this.ForeachToken = original.ForeachToken.CloneNode();
     this.EndForeachToken = original.EndForeachToken.CloneNode();
     this.ForeachBlock = (BlockNode)original.ForeachBlock.Try(a => a.CloneNode(true));
 }
        protected static List<OpenXmlElement> NodesBetween(MatchNodePair first, MatchNodePair last)
        {
            var parent = first.CommonParent(last);

            int indexFirst = parent.ChildElements.IndexOf(first.AscendantNode);
            if (indexFirst == -1)
                throw new InvalidOperationException("Element not found");

            int indexLast = parent.ChildElements.IndexOf(last.AscendantNode);
            if (indexLast == -1)
                throw new InvalidOperationException("Element not found");

            var childs = parent.ChildElements.Where((e, i) => indexFirst < i && i < indexLast).ToList();
            return childs;
        }
        protected void NormalizeInterval(ref MatchNodePair first, ref MatchNodePair last, MatchNode errorHintParent)
        {
            if (first.MatchNode == last.MatchNode)
                throw new ArgumentException("first and last are the same node");

            var chainFirst = ((OpenXmlElement)first.MatchNode).Follow(a => a.Parent).Reverse().ToList();
            var chainLast = ((OpenXmlElement)last.MatchNode).Follow(a => a.Parent).Reverse().ToList();

            var result = chainFirst.Zip(chainLast, (f, l) => new { f, l }).First(a => a.f != a.l);
            AssertNotImportant(chainFirst, result.f, errorHintParent, first.MatchNode, last.MatchNode);
            AssertNotImportant(chainLast, result.l, errorHintParent, last.MatchNode, first.MatchNode);

            first.AscendantNode = result.f;
            last.AscendantNode = result.l;
        }