public object ToRuntimeType(XPathSequence seq) { // FIXME: handle ZeroOrMore|OneOrMore switch (occurence) { case Occurence.One: case Occurence.Optional: if (!seq.MoveNext()) { return(null); } XPathItem item = seq.Current; // FIXME: should check and reject two or // more items?? return(item.TypedValue); } ArrayList al = new ArrayList(); while (seq.MoveNext()) { al.Add(seq.Current.TypedValue); } return(al.ToArray(InternalPool.RuntimeTypeFromXmlTypeCode(schemaType.TypeCode))); // return seq; }
private XmlQualifiedName EvaluateName(XPathSequence iter) { XmlQualifiedName name = Name; if (NameExpr != null) { XPathAtomicValue value = Atomize(new ExprSequenceIterator(iter, NameExpr)); IXmlNamespaceResolver res = iter.Context.NSResolver; switch (value.XmlType.TypeCode) { case XmlTypeCode.QName: name = (XmlQualifiedName)value.ValueAs(typeof(XmlQualifiedName), res); break; case XmlTypeCode.String: try { name = InternalPool.ParseQName(value.Value, res); } catch (ArgumentException ex) { // FIXME: add more info throw new XmlQueryException(String.Format("The evaluation result of the name expression could not be resolved as a valid QName. Evaluation result string is '{0}'.", value.Value)); } break; default: // FIXME: add more info throw new XmlQueryException("A name of an element constructor must be resolved to either a QName or string."); } } return(name); }
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)); }
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)); }
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)); }
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)); }
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)); }