Esempio n. 1
0
 public override void SetXsltContext(XsltContext context)
 {
     if (context == null)
     {
         throw XPathException.Create(Res.Xp_NoContext);
     }
     if (this.xsltContext != context)
     {
         xsltContext = context;
         foreach (Query argument in args)
         {
             argument.SetXsltContext(context);
         }
         XPathResultType[] argTypes = new XPathResultType[args.Count];
         for (int i = 0; i < args.Count; i++)
         {
             argTypes[i] = args[i].StaticType;
         }
         function = xsltContext.ResolveFunction(prefix, name, argTypes);
         // KB article allows to return null, see http://support.microsoft.com/?kbid=324462#6
         if (function == null)
         {
             throw XPathException.Create(Res.Xp_UndefFunc, QName);
         }
     }
 }
Esempio n. 2
0
 public override void SetXsltContext(XsltContext context)
 {
     if (context == null)
     {
         throw XPathException.Create(SR.Xp_NoContext);
     }
     if (this.xsltContext != context)
     {
         xsltContext = context;
         foreach (Query argument in _args)
         {
             argument.SetXsltContext(context);
         }
         XPathResultType[] argTypes = new XPathResultType[_args.Count];
         for (int i = 0; i < _args.Count; i++)
         {
             argTypes[i] = _args[i].StaticType;
         }
         _function = xsltContext.ResolveFunction(prefix, name, argTypes);
         // KB article allows to return null, see http://support.microsoft.com/?kbid=324462#6
         if (_function == null)
         {
             throw XPathException.Create(SR.Xp_UndefFunc, QName);
         }
     }
 }
        // REFACTOR, [....], make this a function on QueryValueModel
        internal XsltFunctionCallOpcode(XsltContext context, IXsltContextFunction function, int argCount)
            : base(OpcodeID.XsltFunction)
        {
            Fx.Assert(null != context && null != function, "");
            this.xsltContext = context;
            this.function = function;
            this.argCount = argCount;

            for (int i = 0; i < function.Maxargs; ++i)
            {
                if (function.ArgTypes[i] == XPathResultType.NodeSet)
                {
                    this.iterList = new List<NodeSequenceIterator>();
                    break;
                }
            }

            // Make sure the return type is valid
            switch (this.function.ReturnType)
            {
                case XPathResultType.String:
                case XPathResultType.Number:
                case XPathResultType.Boolean:
                case XPathResultType.NodeSet:
                    break;

                default:
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new QueryCompileException(QueryCompileError.InvalidType, SR.GetString(SR.QueryFunctionTypeNotSupported, this.function.ReturnType.ToString())));
            }

        }
 public override void SetXsltContext(XsltContext context)
 {
     if (context == null)
     {
         throw XPathException.Create("Xp_NoContext");
     }
     if (base.xsltContext != context)
     {
         base.xsltContext = context;
         foreach (Query query in this.args)
         {
             query.SetXsltContext(context);
         }
         XPathResultType[] argTypes = new XPathResultType[this.args.Count];
         for (int i = 0; i < this.args.Count; i++)
         {
             argTypes[i] = this.args[i].StaticType;
         }
         this.function = base.xsltContext.ResolveFunction(base.prefix, base.name, argTypes);
         if (this.function == null)
         {
             throw XPathException.Create("Xp_UndefFunc", base.QName);
         }
     }
 }
        public override IXsltContextFunction ResolveFunction(string prefix, string name, XPathResultType[] argTypes)
        {
            IXsltContextFunction func = null;

            if (prefix == String.Empty)
            {
                func = s_FunctionTable[name] as IXsltContextFunction;
            }
            else
            {
                string ns = this.LookupNamespace(prefix);
                if (ns == Keywords.s_MsXsltNamespace && name == f_NodeSet)
                {
                    func = s_FuncNodeSet;
                }
                else
                {
                    object extension;
                    func = GetExtentionMethod(ns, name, argTypes, out extension);
                    if (extension == null)
                    {
                        throw new XsltException(Res.Xslt_ScriptInvalidPrefix, prefix);
                    }
                }
            }
            if (func == null)
            {
                throw new XsltException(Res.Xslt_UnknownXsltFunction, name);
            }
            if (argTypes.Length < func.Minargs || func.Maxargs < argTypes.Length)
            {
                throw new XsltException(Res.Xslt_WrongNumberArgs, name, Convert.ToString(argTypes.Length));
            }
            return(func);
        }
Esempio n. 6
0
        public override IXsltContextFunction ResolveFunction(string prefix, string name, XPathResultType[] argTypes)
        {
            IXsltContextFunction func = null;

            if (prefix.Length == 0)
            {
                func = s_FunctionTable[name] as IXsltContextFunction;
            }
            else
            {
                string ns = this.LookupNamespace(prefix);
                if (ns == XmlReservedNs.NsMsxsl && name == f_NodeSet)
                {
                    func = s_FuncNodeSet;
                }
                else
                {
                    object extension;
                    func = GetExtentionMethod(ns, name, argTypes, out extension);
                    if (extension == null)
                    {
                        throw XsltException.Create(Res.Xslt_ScriptInvalidPrefix, prefix);  // BugBug: It's better to say that method 'name' not found
                    }
                }
            }
            if (func == null)
            {
                throw XsltException.Create(Res.Xslt_UnknownXsltFunction, name);
            }
            if (argTypes.Length < func.Minargs || func.Maxargs < argTypes.Length)
            {
                throw XsltException.Create(Res.Xslt_WrongNumberArgs, name, argTypes.Length.ToString(CultureInfo.InvariantCulture));
            }
            return(func);
        }
Esempio n. 7
0
        // REFACTOR, [....], make this a function on QueryValueModel
        internal XsltFunctionCallOpcode(XsltContext context, IXsltContextFunction function, int argCount)
            : base(OpcodeID.XsltFunction)
        {
            Fx.Assert(null != context && null != function, "");
            this.xsltContext = context;
            this.function    = function;
            this.argCount    = argCount;

            for (int i = 0; i < function.Maxargs; ++i)
            {
                if (function.ArgTypes[i] == XPathResultType.NodeSet)
                {
                    this.iterList = new List <NodeSequenceIterator>();
                    break;
                }
            }

            // Make sure the return type is valid
            switch (this.function.ReturnType)
            {
            case XPathResultType.String:
            case XPathResultType.Number:
            case XPathResultType.Boolean:
            case XPathResultType.NodeSet:
                break;

            default:
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new QueryCompileException(QueryCompileError.InvalidType, SR.GetString(SR.QueryFunctionTypeNotSupported, this.function.ReturnType.ToString())));
            }
        }
        private XPathExpr ParseFunctionExpression()
        {
            XPathExpr  expr;
            XPathToken token = this.NextToken(XPathTokenID.Function);

            if (token == null)
            {
                return(null);
            }
            NodeQName name = this.QualifyName(token.Prefix, token.Name);

            this.NextToken(XPathTokenID.LParen, QueryCompileError.InvalidFunction);
            XPathExprList args = new XPathExprList();

            while ((expr = this.ParseExpression()) != null)
            {
                args.Add(expr);
                if (this.NextToken(XPathTokenID.Comma) == null)
                {
                    break;
                }
            }
            XPathExpr expr2 = null;

            if (this.functionLibraries != null)
            {
                QueryFunction function = null;
                for (int i = 0; i < this.functionLibraries.Length; i++)
                {
                    function = this.functionLibraries[i].Bind(name.Name, name.Namespace, args);
                    if (function != null)
                    {
                        expr2 = new XPathFunctionExpr(function, args);
                        break;
                    }
                }
            }
            if ((expr2 == null) && (this.context != null))
            {
                XPathResultType[] argTypes = new XPathResultType[args.Count];
                for (int j = 0; j < args.Count; j++)
                {
                    argTypes[j] = XPathXsltFunctionExpr.ConvertTypeToXslt(args[j].ReturnType);
                }
                string prefix = this.context.LookupPrefix(name.Namespace);
                IXsltContextFunction function2 = this.context.ResolveFunction(prefix, name.Name, argTypes);
                if (function2 != null)
                {
                    expr2 = new XPathXsltFunctionExpr(this.context, function2, args);
                }
            }
            if (expr2 == null)
            {
                this.ThrowError(QueryCompileError.UnsupportedFunction);
            }
            this.NextToken(XPathTokenID.RParen, QueryCompileError.InvalidFunction);
            return(expr2);
        }
        public override IXsltContextFunction ResolveFunction(string prefix, string name,
                                                             System.Xml.XPath.XPathResultType[] ArgTypes)
        {
            //// TODO: Add some useful custom functions ???
            //// TODO: Implement all standart XPath and XSLT function and also build unit tests for them !!!
            ////       http://www.w3.org/TR/xquery-operators/
            ////       http://msdn.microsoft.com/msdnmag/issues/02/03/xml/
            //
            // Functions supported by Microsoft.NET
            //
            //public enum FunctionType
            //{
            //    FuncLast,
            //    FuncPosition,
            //    FuncCount,
            //    FuncID,
            //    FuncLocalName,
            //    FuncNameSpaceUri,
            //    FuncName,
            //    FuncString,
            //    FuncBoolean,
            //    FuncNumber,
            //    FuncTrue,
            //    FuncFalse,
            //    FuncNot,
            //    FuncConcat,
            //    FuncStartsWith,
            //    FuncContains,
            //    FuncSubstringBefore,
            //    FuncSubstringAfter,
            //    FuncSubstring,
            //    FuncStringLength,
            //    FuncNormalize,
            //    FuncTranslate,
            //    FuncLang,
            //    FuncSum,
            //    FuncFloor,
            //    FuncCeiling,
            //    FuncRound,
            //    FuncUserDefined
            //}

            IXsltContextFunction function = XsltContextFunctionBase.ResolveFunction(prefix, name, ArgTypes);

            if (function != null)
            {
                return(function);
            }

            if (m_AdditionalContext != null)
            {
                return(m_AdditionalContext.ResolveFunction(prefix, name, ArgTypes));
            }
            else
            {
                return(null);
            }
        }
Esempio n. 10
0
 public XPathContext AddFunction(string prefix, string name, IXsltContextFunction function)
 {
     if (functions == null)
     {
         functions = new Dictionary <string, Func <IXsltContextFunction> >();
     }
     functions[GetQualifiedName(prefix, name)] = () => function;
     return(this);
 }
Esempio n. 11
0
        public void RegisterFunction(string prefix, string name, IXsltContextFunction function)
        {
            if (function == null)
                throw new ArgumentNullException("function");

            if (name == null)
                throw new ArgumentNullException("name");

            this.functions[prefix + ":" + name] = function;
        }
Esempio n. 12
0
 private FunctionQuery(FunctionQuery other) : base(other) {
     this.function = other.function;
     Query[] tmp = new Query[other.args.Count]; {                
         for (int i = 0; i < tmp.Length; i ++) {
             tmp[i] = Clone(other.args[i]);
         }
         args = tmp;
     }
     this.args = tmp;
 }
 private FunctionQuery(FunctionQuery other) : base(other)
 {
     this.function = other.function;
     Query[] queryArray = new Query[other.args.Count];
     for (int i = 0; i < queryArray.Length; i++)
     {
         queryArray[i] = Query.Clone(other.args[i]);
     }
     this.args = queryArray;
     this.args = queryArray;
 }
 private FunctionQuery(FunctionQuery other) : base(other)
 {
     this.function = other.function;
     Query[] queryArray = new Query[other.args.Count];
     for (int i = 0; i < queryArray.Length; i++)
     {
         queryArray[i] = Query.Clone(other.args[i]);
     }
     this.args = queryArray;
     this.args = queryArray;
 }
Esempio n. 15
0
        /// <inheritdoc/>
        public override IXsltContextFunction ResolveFunction(string prefix, string name, XPathResultType[] argTypes)
        {
            IXsltContextFunction function = null;

            if (prefix == "cldr")
            {
                functions.TryGetValue(name, out function);
            }

            return(function);
        }
Esempio n. 16
0
 private FunctionQuery(FunctionQuery other) : base(other)
 {
     this.function = other.function;
     Query[] tmp = new Query[other.args.Count]; {
         for (int i = 0; i < tmp.Length; i++)
         {
             tmp[i] = Clone(other.args[i]);
         }
         args = tmp;
     }
     this.args = tmp;
 }
Esempio n. 17
0
        public void RegisterFunction(string prefix, string name, IXsltContextFunction function)
        {
            if (function == null)
            {
                throw new ArgumentNullException("function");
            }

            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            this.Functions[prefix + ":" + name] = function;
        }
Esempio n. 18
0
        public override object Evaluate(BaseIterator iter)
        {
            XPathResultType[]    argTypes            = this.GetArgTypes(iter);
            IXsltContextFunction xsltContextFunction = null;
            XsltContext          xsltContext         = iter.NamespaceManager as XsltContext;

            if (xsltContext != null)
            {
                if (this.resolvedName)
                {
                    xsltContextFunction = xsltContext.ResolveFunction(this._name, argTypes);
                }
                else
                {
                    xsltContextFunction = xsltContext.ResolveFunction(this._name.Namespace, this._name.Name, argTypes);
                }
            }
            if (xsltContextFunction == null)
            {
                throw new XPathException("function " + this._name.ToString() + " not found");
            }
            object[] array = new object[this._args.Count];
            if (xsltContextFunction.Maxargs != 0)
            {
                XPathResultType[] argTypes2 = xsltContextFunction.ArgTypes;
                for (int i = 0; i < this._args.Count; i++)
                {
                    XPathResultType type;
                    if (argTypes2 == null)
                    {
                        type = XPathResultType.Any;
                    }
                    else if (i < argTypes2.Length)
                    {
                        type = argTypes2[i];
                    }
                    else
                    {
                        type = argTypes2[argTypes2.Length - 1];
                    }
                    Expression expression = (Expression)this._args[i];
                    object     obj        = expression.EvaluateAs(iter, type);
                    array[i] = obj;
                }
            }
            return(xsltContextFunction.Invoke(xsltContext, array, iter.Current));
        }
Esempio n. 19
0
        /// <summary>
        /// Override for XsltContext method used to resolve methods
        /// </summary>
        /// <param name="prefix">Namespace prefix for function</param>
        /// <param name="name">Name of function</param>
        /// <param name="ArgTypes">Array of XPathResultType</param>
        /// <returns>Implementation of IXsltContextFunction</returns>
        public override IXsltContextFunction ResolveFunction(string prefix, string name, XPathResultType[] ArgTypes)
        {
            IXsltContextFunction func = null;

            switch (name)
            {
            case "compare":
                func = new CompareFunction();
                break;

            case "regex":
                func = new RegexFunction();
                break;

            default:
                break;
            }
            return(func);
        }
Esempio n. 20
0
        /// <summary>
        /// Resolves a function reference and return an
        /// <see cref="IXsltContextFunction"/> representing the function. The
        /// <see cref="IXsltContextFunction"/> is used at execution time to get
        /// the return value of the function.
        /// </summary>
        /// <param name="prefix">The prefix of the function as it appears in
        /// the XPath expression</param>
        /// <param name="name">The name of the function</param>
        /// <param name="ArgTypes">An array of argument types for the function
        /// being resolved. This allows you to select between methods with the
        /// same name (for example, overloaded methods).</param>
        /// <returns>An <see cref="IXsltContextFunction"/> representing the
        /// function</returns>
        public override IXsltContextFunction ResolveFunction(string prefix,
                                                             string name, XPathResultType[] ArgTypes)
        {
            IXsltContextFunction function = null;

            switch (name)
            {
            case "matches-regex":
                function = new MatchesRegexFunction();
                break;

            case "resolve-name":
                function = new ResolveNameFunction();
                break;

            default:
                break;
            }

            return(function);
        }
        public override IXsltContextFunction ResolveFunction(string prefix, string name, XPathResultType[] argTypes)
        {
            if (argTypes == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("argTypes");
            }
            string str = this.LookupNamespace(prefix);

            for (int i = 0; i < functions.Length; i++)
            {
                if ((functions[i].name == name) && (functions[i].ns == str))
                {
                    IXsltContextFunction function = functions[i].function;
                    if ((argTypes.Length <= function.Maxargs) && (argTypes.Length >= function.Minargs))
                    {
                        return(function);
                    }
                }
            }
            return(null);
        }
Esempio n. 22
0
        /// <summary>
        /// Override for XsltContext method used to resolve methods
        /// </summary>
        /// <param name="prefix">Namespace prefix for function</param>
        /// <param name="name">Name of function</param>
        /// <param name="ArgTypes">Array of XPathResultType</param>
        /// <returns>Implementation of IXsltContextFunction</returns>
        public override IXsltContextFunction ResolveFunction(string prefix, string name, XPathResultType[] ArgTypes)
        {
            IXsltContextFunction func = null;

            switch (name)
            {
            case "compare":
                if (ArgTypes.Length == 2)
                {
                    func = new CompareFunction();
                }
                else if (ArgTypes.Length == 1)
                {
                    func = new CompareFunctionWithVariable();
                }
                break;

            default:
                break;
            }
            return(func);
        }
 internal XsltFunctionCallOpcode(XsltContext context, IXsltContextFunction function, int argCount) : base(OpcodeID.XsltFunction)
 {
     this.xsltContext = context;
     this.function = function;
     this.argCount = argCount;
     for (int i = 0; i < function.Maxargs; i++)
     {
         if (function.ArgTypes[i] == XPathResultType.NodeSet)
         {
             this.iterList = new List<NodeSequenceIterator>();
             break;
         }
     }
     switch (this.function.ReturnType)
     {
         case XPathResultType.Number:
         case XPathResultType.String:
         case XPathResultType.Boolean:
         case XPathResultType.NodeSet:
             return;
     }
     throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new QueryCompileException(QueryCompileError.InvalidType, System.ServiceModel.SR.GetString("QueryFunctionTypeNotSupported", new object[] { this.function.ReturnType.ToString() })));
 }
Esempio n. 24
0
 internal XsltFunctionCallOpcode(XsltContext context, IXsltContextFunction function, int argCount) : base(OpcodeID.XsltFunction)
 {
     this.xsltContext = context;
     this.function    = function;
     this.argCount    = argCount;
     for (int i = 0; i < function.Maxargs; i++)
     {
         if (function.ArgTypes[i] == XPathResultType.NodeSet)
         {
             this.iterList = new List <NodeSequenceIterator>();
             break;
         }
     }
     switch (this.function.ReturnType)
     {
     case XPathResultType.Number:
     case XPathResultType.String:
     case XPathResultType.Boolean:
     case XPathResultType.NodeSet:
         return;
     }
     throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new QueryCompileException(QueryCompileError.InvalidType, System.ServiceModel.SR.GetString("QueryFunctionTypeNotSupported", new object[] { this.function.ReturnType.ToString() })));
 }
Esempio n. 25
0
        public void AddFunction(string prefix, string name, IXsltContextFunction function)
        {
            var key = new XmlName(name, prefix ?? string.Empty);

            AddFunction(key, function);
        }
Esempio n. 26
0
		public XPathContext AddFunction(string prefix, string name, IXsltContextFunction function)
		{
			functions[GetQualifiedName(prefix, name)] = () => function;
			return this;
		}
 internal Function(string ns, string name, IXsltContextFunction function)
 {
     this.ns       = ns;
     this.name     = name;
     this.function = function;
 }
Esempio n. 28
0
		public void AddFunction(XmlName name, IXsltContextFunction function)
		{
			EnsureFunctions()[name] = function;
		}
Esempio n. 29
0
		public void AddFunction(string prefix, string name, IXsltContextFunction function)
		{
			var key = new XmlName(name, prefix ?? string.Empty);
			AddFunction(key, function);
		}
Esempio n. 30
0
        private void InvokeFunction(XPathNavigator qy)
        {
            IXsltContextFunction function = this.Function;

            // calculate arguments:
            Debug.Assert(_ArgArray != null && _ArgArray.Length == _ArgList.Count);
            for (int i = _ArgList.Count - 1; 0 <= i; i--)
            {
                IQuery arg = (IQuery)_ArgList[i];
                if (arg.ReturnType() == XPathResultType.NodeSet)
                {
                    _ArgArray[i] = new XPathQueryIterator(arg, qy.Clone());
                }
                else
                {
                    _ArgArray[i] = arg.getValue(qy, null);
                }
            }

            try {
                object result = function.Invoke(_XsltContext, _ArgArray, qy);

                if (result == null)
                {
                    _ResultQuery = new OperandQuery(String.Empty, XPathResultType.String);
                }
                else
                {
                    XPathResultType returnedType = function.ReturnType;
                    if (returnedType == XPathResultType.Any)
                    {
                        // If function is untyped get returned type from real result
                        returnedType = XsltCompileContext.GetXPathType(result.GetType());
                    }
                    switch (returnedType)
                    {
                    case XPathResultType.String:
                        // trick. As soon XPathResultType.Navigator will be distinct type rid of from it.
                        //_ResultQuery = new OperandQuery( result, XPathResultType.String );
                        if (result is XPathNavigator)
                        {
                            _ResultQuery = new NavigatorQuery((XPathNavigator)result);
                        }
                        else
                        {
                            _ResultQuery = new OperandQuery(result, XPathResultType.String);
                        }
                        break;

                    case XPathResultType.Boolean:
                        _ResultQuery = new OperandQuery(result, XPathResultType.Boolean);
                        break;

                    case XPathResultType.Number:
                        _ResultQuery = new OperandQuery(XmlConvert.ToXPathDouble(result), XPathResultType.Number);
                        break;

                    case XPathResultType.NodeSet:
                        if (result is ResetableIterator)
                        {
                            _ResultQuery = new XmlIteratorQuery((ResetableIterator)result);
                        }
                        else
                        {
                            Debug.Assert(false, "Unexpected type of XPathNodeIterator");
                            throw new NotSupportedException(Res.GetString(Res.XmlUnsupportedType, result.GetType().FullName));
                        }
                        break;

//                  case XPathResultType.Navigator :
//                      _ResultQuery = new NavigatorQuery((XPathNavigator)result);
//                      break;
                    default:
                        _ResultQuery = new OperandQuery(result.ToString(), XPathResultType.String);
                        break;
                    }
                }
            }
            catch (Exception ex) {
                string qname = _Prefix != string.Empty ? _Prefix + ":" + _Name : _Name;
                throw new XsltException(Res.Xslt_FunctionFailed, new string[] { qname }, ex);
            }
        }
 internal Function(string ns, string name, IXsltContextFunction function)
 {
     this.ns = ns;
     this.name = name;
     this.function = function;
 }
Esempio n. 32
0
 public XPathContext AddFunction(string prefix, string name, IXsltContextFunction function)
 {
     functions[GetQualifiedName(prefix, name)] = () => function;
     return(this);
 }
Esempio n. 33
0
 internal XPathXsltFunctionExpr(XsltContext context, IXsltContextFunction function, XPathExprList subExpr)
     : base(XPathExprType.XsltFunction, ConvertTypeFromXslt(function.ReturnType), subExpr)
 {
     this.function = function;
     this.context = context;
 }
Esempio n. 34
0
		public XPathContext AddFunction(string prefix, string name, IXsltContextFunction function)
		{
			if (functions == null)
				functions = new Dictionary<string, Func<IXsltContextFunction>>();
			functions[GetQualifiedName(prefix, name)] = () => function;
			return this;
		}
Esempio n. 35
0
 public void AddFunction(XmlName name, IXsltContextFunction function)
 {
     EnsureFunctions()[name] = function;
 }
 public override void SetXsltContext(XsltContext context)
 {
     if (context == null)
     {
         throw XPathException.Create("Xp_NoContext");
     }
     if (base.xsltContext != context)
     {
         base.xsltContext = context;
         foreach (Query query in this.args)
         {
             query.SetXsltContext(context);
         }
         XPathResultType[] argTypes = new XPathResultType[this.args.Count];
         for (int i = 0; i < this.args.Count; i++)
         {
             argTypes[i] = this.args[i].StaticType;
         }
         this.function = base.xsltContext.ResolveFunction(base.prefix, base.name, argTypes);
         if (this.function == null)
         {
             throw XPathException.Create("Xp_UndefFunc", base.QName);
         }
     }
 }
Esempio n. 37
0
        XPathExpr ParseFunctionExpression()
        {
            XPathToken functionToken = this.NextToken(XPathTokenID.Function);

            if (null == functionToken)
            {
                return(null);
            }

            NodeQName functionName = this.QualifyName(functionToken.Prefix, functionToken.Name);

            this.NextToken(XPathTokenID.LParen, QueryCompileError.InvalidFunction);

            XPathExprList args = new XPathExprList();

            // Read in arguments
            XPathExpr arg;

            while (null != (arg = this.ParseExpression()))
            {
                args.Add(arg);
                if (null == this.NextToken(XPathTokenID.Comma))
                {
                    break;
                }
            }

            // Bind to the function
            // Try each library until we can bind the function
            XPathExpr functionImpl = null;

            if (null != this.functionLibraries)
            {
                QueryFunction fun = null;
                for (int i = 0; i < this.functionLibraries.Length; ++i)
                {
                    if (null != (fun = this.functionLibraries[i].Bind(functionName.Name, functionName.Namespace, args)))
                    {
                        functionImpl = new XPathFunctionExpr(fun, args);
                        break;
                    }
                }
            }

            // Try to bind using the XsltContext
            if (null == functionImpl && this.context != null)
            {
                XPathResultType[] argTypes = new XPathResultType[args.Count];
                for (int i = 0; i < args.Count; ++i)
                {
                    argTypes[i] = XPathXsltFunctionExpr.ConvertTypeToXslt(args[i].ReturnType);
                }
                string prefix = this.context.LookupPrefix(functionName.Namespace);
                IXsltContextFunction xsltFun = this.context.ResolveFunction(prefix, functionName.Name, argTypes);
                if (xsltFun != null)
                {
                    functionImpl = new XPathXsltFunctionExpr(this.context, xsltFun, args);
                }
            }

            if (null == functionImpl)
            {
                this.ThrowError(QueryCompileError.UnsupportedFunction);
            }

            this.NextToken(XPathTokenID.RParen, QueryCompileError.InvalidFunction);
            return(functionImpl);
        }
Esempio n. 38
0
 internal XPathXsltFunctionExpr(XsltContext context, IXsltContextFunction function, XPathExprList subExpr)
     : base(XPathExprType.XsltFunction, ConvertTypeFromXslt(function.ReturnType), subExpr)
 {
     this.function = function;
     this.context  = context;
 }