示例#1
0
        internal XPathSequence ResolveVariable(XmlQualifiedName name)
        {
            object obj = currentVariables [name];

            if (obj == null && contextManager.Arguments != null)
            {
                obj = contextManager.Arguments.GetParameter(name.Name, name.Namespace);
            }
            if (obj == null)
            {
                return(new XPathEmptySequence(this));
            }
            XPathSequence seq = obj as XPathSequence;

            if (seq != null)
            {
                return(seq);
            }
            XPathItem item = obj as XPathItem;

            if (item == null)
            {
                item = new XPathAtomicValue(obj, InternalPool.GetBuiltInType(InternalPool.XmlTypeCodeFromRuntimeType(obj.GetType(), true)));
            }
            return(new SingleItemIterator(item, this));
        }
示例#2
0
        internal void CheckSchemaTypeName(XmlQualifiedName name)
        {
            XmlSchemaType type = InternalPool.GetBuiltInType(name);

            if (type != null)
            {
                return;
            }
            throw new XmlQueryCompileException(String.Format("Unresolved schema type name: {0}", name));
        }
示例#3
0
        internal XmlSchemaType ResolveSchemaType(XmlQualifiedName name)
        {
            XmlSchemaType type = InternalPool.GetBuiltInType(name);

            if (type != null)
            {
                return(type);
            }
            type = inScopeSchemas.GlobalTypes [name] as XmlSchemaType;
            if (type != null)
            {
                return(type);
            }
            return(null);
        }
        public static object FnTrace(XQueryContext ctx, object value, string label)
        {
            if (value == null)
            {
                return(new XPathEmptySequence(ctx));
            }
            XPathSequence seq = value as XPathSequence;

            if (seq == null)
            {
                XPathAtomicValue av = value as XPathAtomicValue;
                if (av == null)
                {
                    av = new XPathAtomicValue(value,
                                              InternalPool.GetBuiltInType(
                                                  InternalPool.XmlTypeCodeFromRuntimeType(
                                                      value.GetType(), true)));
                }
                seq = new SingleItemIterator(av, ctx);
            }
            return(new TracingIterator(seq, label));
        }
示例#5
0
        public override object Invoke(XPathSequence current, object [] args)
        {
            MethodInfo mi = methods [args.Length] as MethodInfo;

            if (mi == null)
            {
                throw new ArgumentException("The number of custom function parameter does not match with the registered method's signature.");
            }
            ParameterInfo [] prms = mi.GetParameters();

            // Use Evidence and PermissionSet.Demand() here
            // before invoking external function.
            Evidence e = current.Context.StaticContext.Evidence;

            if (e != null)
            {
                SecurityManager.ResolvePolicy(e).Demand();
            }

            Type t      = prms.Length > 0 ? prms [0].ParameterType : null;
            bool ctxSeq = mi.GetCustomAttributes(
                typeof(XQueryFunctionContextAttribute),
                false).Length > 0;

            if (t == typeof(XQueryContext))
            {
                ArrayList pl = new ArrayList(args);
                pl.Insert(0, current.Context);
                args = pl.ToArray();
            }
            else if (ctxSeq)
            {
                ArrayList pl = new ArrayList(args);
                pl.Insert(0, current);
                args = pl.ToArray();
            }

            if (args.Length != prms.Length)
            {
                throw new XmlQueryException(String.Format("Argument numbers were different for function {0}. Signature requires {1} while actual call was {2}.", mi.Name, prms.Length, args.Length));
            }

            // If native parameter type is XPathSequence and the actual values are not, adjust them
            for (int i = 0; i < args.Length; i++)
            {
                if (prms [i].ParameterType == typeof(XPathSequence) && !(args [i] is XPathSequence))
                {
                    XPathItem item = args [i] as XPathItem;
                    if (item == null)
                    {
                        item = args [i] == null ? null : new XPathAtomicValue(args [i], InternalPool.GetBuiltInType(InternalPool.XmlTypeCodeFromRuntimeType(prms [i].ParameterType, true)));
                    }
                    if (item == null)
                    {
                        args [i] = new XPathEmptySequence(current.Context);
                    }
                    else
                    {
                        args [i] = new SingleItemIterator(item, current.Context);
                    }
                }
            }

            return(mi.Invoke(null, args));
        }