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."); } }
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()); }