예제 #1
0
        internal static SequenceType Create(Type cliType)
        {
            // typed Array
            if (cliType.IsArray)
            {
                return(Create(InternalPool.XmlTypeCodeFromRuntimeType(cliType.GetElementType(), true), Occurence.ZeroOrMore));
            }
//			if (cliType.GetInterface ("System.Collections.IEnumerable") != null)
//				return Create (XmlTypeCode.Item, Occurence.ZeroOrMore);
            if (cliType == typeof(XmlQualifiedName))
            {
                return(QName);
            }
            if (cliType == typeof(XPathNavigator) || cliType.IsSubclassOf(typeof(XPathNavigator)))
            {
                return(Node);
            }
            if (cliType == typeof(XPathAtomicValue))
            {
                return(SingleAnyAtomic);
            }
            if (cliType == typeof(XPathItem))
            {
                return(SingleItem);
            }
            // FIXME: handle Nullable type
            return(Create(InternalPool.XmlTypeCodeFromRuntimeType(cliType, true), Occurence.One));
        }
예제 #2
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));
        }
        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));
        }
예제 #4
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));
        }