Ejemplo n.º 1
0
        private bool GetElement(TreeNode <string> treeEl, PatternElement patternEl, out object data)
        {
            data = string.Empty;
            if (treeEl.IsRoot)
            {
                return(false);
            }
            if (treeEl.Level <= patternEl.Level)
            {
                var requiredElement = treeEl.Parent.FindTreeNode(p =>
                                                                 p.Data == patternEl.FieldName &&
                                                                 p.Level == patternEl.Level &&
                                                                 p.Parent.NodeName == patternEl.ParentName);
                data = requiredElement != null?GetElementData(requiredElement) : null;

                return(data != null);
            }

            if (treeEl.Level > patternEl.Level)
            {
                var upperNode = LevelUp(treeEl, treeEl.Level - patternEl.Level);

                var requiredElement =
                    upperNode.Parent.FindTreeNode(p =>
                                                  p.Data == patternEl.FieldName &&
                                                  p.Level == patternEl.Level &&
                                                  p.Parent.NodeName == patternEl.ParentName);
                data = requiredElement != null?GetElementData(requiredElement) : null;

                return(data != null);
            }
            return(true);
        }
Ejemplo n.º 2
0
        public bool GetAction(
            NodeType type,
            TreeNode <string> treeEl,
            PatternElement patternEl,
            out object data)
        {
            switch (type)
            {
            case NodeType.Field:
                return(GetElement(treeEl, patternEl, out data));

            case NodeType.Array:
                return(GetInnerArray(treeEl, patternEl, out data));

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }
Ejemplo n.º 3
0
        private bool GetInnerArray(TreeNode <string> treeEl, PatternElement patternEl, out object data)
        {
            data = null;
            var result        = new List <string>();
            var innerElements = treeEl.Parent.FindTreeNodes(p =>
                                                            p.Data == patternEl.FieldName &&
                                                            p.Level == patternEl.Level - 1 &&
                                                            p.Parent.NodeName == patternEl.ParentName);

            foreach (var element in innerElements)
            {
                var elData = GetElementData(element);
                result.Add(elData);
            }

            data = result.ToArray();
            return(true);
        }