Exemplo 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);
         }
     }
 }
Exemplo n.º 2
0
 public override IXsltContextFunction ResolveFunction(string prefix, string name, XPathResultType[] argTypes)
 {
   XsltFunction function;
   if (functions.TryGetValue(name, out function))
     return function;
   return baseContext.ResolveFunction(prefix, name, argTypes);
 }
Exemplo n.º 3
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));
        }
Exemplo n.º 4
0
 public override IXsltContextFunction ResolveFunction(
     string prefix,
     string name,
     XPathResultType[] argTypes
     )
 {
     return(context.ResolveFunction(prefix, name, argTypes));
 }
Exemplo n.º 5
0
        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);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// When overridden in a derived class, resolves a function reference and returns an
        /// <see cref="T:System.Xml.Xsl.IXsltContextFunction"/> representing the function. The <see cref="T:System.Xml.Xsl.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="T:System.Xml.Xsl.IXsltContextFunction"/> representing the function.
        /// </returns>
        public override IXsltContextFunction ResolveFunction(string prefix, string name, XPathResultType[] argTypes)
        {
            if (_functionResolver != null)
            {
                var function = _functionResolver.ResolveFunction(prefix, name, argTypes);
                if (function != null)
                {
                    return(function);
                }
            }

            return(_baseContext.ResolveFunction(prefix, name, argTypes));
        }