コード例 #1
0
        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;
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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;
        }
コード例 #5
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;
        }
コード例 #6
0
 public abstract object Evaluate(FunctionArgs args);