public override object Evaluate(FunctionArgs args) { if (args.Arguments.Length != 0) { throw new XPathException("No arguments allowed in position()"); } var item = args.Context as IXPathItem; if (item == null) { return -1; } var parent = item.GetParent(); if (parent == null) { return -1; } var children = parent.GetChildren().ToArray(); for (var n = 0; n < children.Length; n++) { if (children[n] == args.Context) { return n + 1; } } return -1; }
public object EvaluateFunction([NotNull] Function function, [NotNull] [ItemNotNull] Opcode[] arguments, [CanBeNull] object context) { var func = XPathService.Functions.FirstOrDefault(f => string.Equals(f.Name, function.Name, StringComparison.OrdinalIgnoreCase)); if (func == null) { throw new XPathException("Function not found: " + function.Name); } var args = new FunctionArgs(this, arguments, context); return func.Evaluate(args); }
public override object Evaluate(FunctionArgs args) { if (args.Arguments.Length != 2) { throw new XPathException("Too many or to few arguments in EndsWith()"); } var a0 = args.Arguments[0].Evaluate(args.XPathExpression, args.Context); var a1 = args.Arguments[1].Evaluate(args.XPathExpression, args.Context); if (!(a0 is string && a1 is string)) { throw new XPathException("String expression expected in EndsWith()"); } return a0.ToString().EndsWith(a1.ToString(), StringComparison.OrdinalIgnoreCase); }
public override object Evaluate(FunctionArgs args) { if (args.Arguments.Length != 2) { throw new XPathException("Too many or to few arguments in Contains()"); } var a0 = args.Arguments[0].Evaluate(args.XPathExpression, args.Context); var a1 = args.Arguments[1].Evaluate(args.XPathExpression, args.Context); if (!(a0 is string && a1 is string)) { throw new XPathException("String expression expected in Contains()"); } return a0.ToString().IndexOf(a1.ToString(), StringComparison.InvariantCulture) >= 0; }
public override object Evaluate(FunctionArgs args) { if (args.Arguments.Length != 0) { throw new XPathException("No arguments allowed in last()"); } var item = args.Context as IXPathItem; if (item == null) { return -1; } var parent = item.GetParent(); if (parent != null) { return parent.GetChildren().Count(); } return -1; }
public abstract object Evaluate(FunctionArgs args);