예제 #1
0
        public override XPathNodeIterator Clone()
        {
            XPathQueryIterator clone = new XPathQueryIterator(query.Clone(), nav.Clone());

            clone.MoveToPosition(this.CurrentPosition);
            Debug.Assert(this.CurrentPosition == clone.CurrentPosition);
            return(clone);
        }
예제 #2
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);
            }
        }
예제 #3
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);
            }
        }
예제 #4
0
 public override XPathNodeIterator Clone() {
     XPathQueryIterator clone = new XPathQueryIterator(query.Clone(), nav.Clone());
     clone.MoveToPosition(this.CurrentPosition);
     Debug.Assert(this.CurrentPosition == clone.CurrentPosition);
     return clone;
 }