public string Evaluate(WalkedPath walkedPath)
        {
            switch (_arrayPathType)
            {
            case ArrayPathType.AUTO_EXPAND:
                return(_canonicalForm);

            case ArrayPathType.EXPLICIT_INDEX:
                return(_arrayIndex);

            case ArrayPathType.HASH:
                MatchedElement element = walkedPath.ElementFromEnd(_ref.GetPathIndex()).MatchedElement;
                return(element.GetHashCount().ToString());

            case ArrayPathType.TRANSPOSE:
                string key = _transposePathElement.Evaluate(walkedPath);
                return(VerifyStringIsNonNegativeInteger(key));

            case ArrayPathType.REFERENCE:
            {
                MatchedElement lpe = walkedPath.ElementFromEnd(_ref.GetPathIndex()).MatchedElement;
                string         keyPart;

                if (_ref is IPathAndGroupReference pagr)
                {
                    keyPart = lpe.GetSubKeyRef(pagr.GetKeyGroup());
                }
                else
                {
                    keyPart = lpe.GetSubKeyRef(0);
                }

                return(VerifyStringIsNonNegativeInteger(keyPart));
            }

            default:
                throw new InvalidOperationException("ArrayPathType enum added two without updating this switch statement.");
            }
        }
        /**
         * This method is used when the TransposePathElement is used on the LFH as data.
         *
         * Aka, normal "evaluate" returns either a Number or a string.
         *
         * @param walkedPath WalkedPath to evaluate against
         * @return The data specified by this TransposePathElement.
         */
        public JToken ObjectEvaluate(WalkedPath walkedPath)
        {
            // Grap the data we need from however far up the tree we are supposed to go
            PathStep pathStep = walkedPath.ElementFromEnd(_upLevel);

            if (pathStep == null)
            {
                return(null);
            }

            var treeRef = pathStep.TreeRef;

            // Now walk down from that level using the subPathReader
            if (_subPathReader == null)
            {
                return(treeRef);
            }
            else
            {
                return(_subPathReader.Read(treeRef, walkedPath));
            }
        }
        public string Evaluate(WalkedPath walkedPath)
        {
            // Walk thru our tokens and build up a string
            // Use the supplied Path to fill in our token References
            StringBuilder output = new StringBuilder();

            foreach (object token in _tokens)
            {
                if (token is string stoken)
                {
                    output.Append(stoken);
                }
                else
                {
                    AmpReference   ref_           = (AmpReference)token;
                    MatchedElement matchedElement = walkedPath.ElementFromEnd(ref_.GetPathIndex()).MatchedElement;
                    string         value          = matchedElement.GetSubKeyRef(ref_.GetKeyGroup());
                    output.Append(value);
                }
            }

            return(output.ToString());
        }