コード例 #1
0
 public static bool ToBoolean(object arg)
 {
     if (arg == null)
     {
         throw new ArgumentNullException();
     }
     if (arg is bool)
     {
         return((bool)arg);
     }
     if (arg is double)
     {
         double num = (double)arg;
         return(num != 0.0 && !double.IsNaN(num));
     }
     if (arg is string)
     {
         return(((string)arg).Length != 0);
     }
     if (arg is XPathNodeIterator)
     {
         XPathNodeIterator xpathNodeIterator = (XPathNodeIterator)arg;
         return(xpathNodeIterator.MoveNext());
     }
     if (arg is XPathNavigator)
     {
         return(XPathFunctions.ToBoolean(((XPathNavigator)arg).SelectChildren(XPathNodeType.All)));
     }
     throw new ArgumentException();
 }
コード例 #2
0
        public override object Evaluate(BaseIterator iter)
        {
            String strArgs;
            object val = arg0.Evaluate(iter);

            XPathNodeIterator valItr = val as XPathNodeIterator;

            if (valItr != null)
            {
                strArgs = "";
                while (valItr.MoveNext())
                {
                    strArgs += valItr.Current.Value + " ";
                }
            }
            else
            {
                strArgs = XPathFunctions.ToString(val);
            }

            XPathNavigator n       = iter.Current.Clone();
            ArrayList      rgNodes = new ArrayList();

            string [] ids = strArgs.Split(rgchWhitespace);
            for (int i = 0; i < ids.Length; i++)
            {
                if (n.MoveToId(ids [i]))
                {
                    rgNodes.Add(n.Clone());
                }
            }

            rgNodes.Sort(XPathNavigatorComparer.Instance);
            return(new ListIterator(iter, rgNodes));
        }
コード例 #3
0
        public override object Evaluate(BaseIterator iter)
        {
            object            obj = this.arg0.Evaluate(iter);
            XPathNodeIterator xpathNodeIterator = obj as XPathNodeIterator;
            string            text;

            if (xpathNodeIterator != null)
            {
                text = string.Empty;
                while (xpathNodeIterator.MoveNext())
                {
                    XPathNavigator xpathNavigator = xpathNodeIterator.Current;
                    text = text + xpathNavigator.Value + " ";
                }
            }
            else
            {
                text = XPathFunctions.ToString(obj);
            }
            XPathNavigator xpathNavigator2 = iter.Current.Clone();
            ArrayList      arrayList       = new ArrayList();

            string[] array = text.Split(XPathFunctionId.rgchWhitespace);
            for (int i = 0; i < array.Length; i++)
            {
                if (xpathNavigator2.MoveToId(array[i]))
                {
                    arrayList.Add(xpathNavigator2.Clone());
                }
            }
            arrayList.Sort(XPathNavigatorComparer.Instance);
            return(new ListIterator(iter, arrayList));
        }
コード例 #4
0
 public static double ToNumber(object arg)
 {
     if (arg == null)
     {
         throw new ArgumentNullException();
     }
     if (arg is BaseIterator || arg is XPathNavigator)
     {
         arg = XPathFunctions.ToString(arg);
     }
     if (arg is string)
     {
         string arg2 = arg as string;
         return(XPathFunctions.ToNumber(arg2));
     }
     if (arg is double)
     {
         return((double)arg);
     }
     if (arg is bool)
     {
         return(Convert.ToDouble((bool)arg));
     }
     throw new ArgumentException();
 }
コード例 #5
0
 public override object Evaluate(BaseIterator iter)
 {
     if (arg0 == null)
     {
         return(XPathFunctions.ToNumber(iter.Current.Value));
     }
     return(arg0.EvaluateNumber(iter));
 }
コード例 #6
0
 public override object Evaluate(BaseIterator iter)
 {
     if (this.arg0 == null)
     {
         return(XPathFunctions.ToBoolean(iter.Current.Value));
     }
     return(this.arg0.EvaluateBoolean(iter));
 }
コード例 #7
0
        public override object Evaluate(BaseIterator iter)
        {
            XPathNodeIterator xpathNodeIterator = this.arg0.EvaluateNodeSet(iter);
            double            num = 0.0;

            while (xpathNodeIterator.MoveNext())
            {
                XPathNavigator xpathNavigator = xpathNodeIterator.Current;
                num += XPathFunctions.ToNumber(xpathNavigator.Value);
            }
            return(num);
        }
コード例 #8
0
        public override object Evaluate(BaseIterator iter)
        {
            XPathNodeIterator itr = arg0.EvaluateNodeSet(iter);

            double sum = 0;

            while (itr.MoveNext())
            {
                sum += XPathFunctions.ToNumber(itr.Current.Value);
            }

            return(sum);
        }
コード例 #9
0
        public override bool MoveNextCore()
        {
            if (finished)
            {
                return(false);
            }
            while (_iter.MoveNext())
            {
                switch (resType)
                {
                case XPathResultType.Number:
                    if (_pred.EvaluateNumber(_iter) != _iter.ComparablePosition)
                    {
                        continue;
                    }
                    break;

                case XPathResultType.Any:
                {
                    object result = _pred.Evaluate(_iter);
                    if (result is double)
                    {
                        if ((double)result != _iter.ComparablePosition)
                        {
                            continue;
                        }
                    }
                    else if (!XPathFunctions.ToBoolean(result))
                    {
                        continue;
                    }
                }
                break;

                default:
                    if (!_pred.EvaluateBoolean(_iter))
                    {
                        continue;
                    }
                    break;
                }

                return(true);
            }
            finished = true;
            return(false);
        }
コード例 #10
0
        public virtual double EvaluateNumber(BaseIterator iter)
        {
            XPathResultType xpathResultType = this.GetReturnType(iter);
            object          obj;

            if (xpathResultType == XPathResultType.NodeSet)
            {
                obj             = this.EvaluateString(iter);
                xpathResultType = XPathResultType.String;
            }
            else
            {
                obj = this.Evaluate(iter);
            }
            if (xpathResultType == XPathResultType.Any)
            {
                xpathResultType = Expression.GetReturnType(obj);
            }
            switch (xpathResultType)
            {
            case XPathResultType.Number:
                if (obj is double)
                {
                    return((double)obj);
                }
                if (obj is IConvertible)
                {
                    return(((IConvertible)obj).ToDouble(CultureInfo.InvariantCulture));
                }
                return((double)obj);

            case XPathResultType.String:
                return(XPathFunctions.ToNumber((string)obj));

            case XPathResultType.Boolean:
                return((!(bool)obj) ? 0.0 : 1.0);

            case XPathResultType.NodeSet:
                return(XPathFunctions.ToNumber(this.EvaluateString(iter)));

            case XPathResultType.Navigator:
                return(XPathFunctions.ToNumber(((XPathNavigator)obj).Value));

            default:
                throw new XPathException("invalid node type");
            }
        }
コード例 #11
0
 public override bool MoveNextCore()
 {
     if (this.finished)
     {
         return(false);
     }
     while (this._iter.MoveNext())
     {
         XPathResultType xpathResultType = this.resType;
         if (xpathResultType != XPathResultType.Number)
         {
             if (xpathResultType != XPathResultType.Any)
             {
                 if (!this._pred.EvaluateBoolean(this._iter))
                 {
                     continue;
                 }
             }
             else
             {
                 object obj = this._pred.Evaluate(this._iter);
                 if (obj is double)
                 {
                     if ((double)obj != (double)this._iter.ComparablePosition)
                     {
                         continue;
                     }
                 }
                 else if (!XPathFunctions.ToBoolean(obj))
                 {
                     continue;
                 }
             }
         }
         else if (this._pred.EvaluateNumber(this._iter) != (double)this._iter.ComparablePosition)
         {
             continue;
         }
         return(true);
     }
     this.finished = true;
     return(false);
 }
コード例 #12
0
        public virtual string EvaluateString(BaseIterator iter)
        {
            object          obj        = this.Evaluate(iter);
            XPathResultType returnType = this.GetReturnType(iter);

            if (returnType == XPathResultType.Any)
            {
                returnType = Expression.GetReturnType(obj);
            }
            switch (returnType)
            {
            case XPathResultType.Number:
            {
                double d = (double)obj;
                return(XPathFunctions.ToString(d));
            }

            case XPathResultType.String:
                return((string)obj);

            case XPathResultType.Boolean:
                return((!(bool)obj) ? "false" : "true");

            case XPathResultType.NodeSet:
            {
                BaseIterator baseIterator = (BaseIterator)obj;
                if (baseIterator == null || !baseIterator.MoveNext())
                {
                    return(string.Empty);
                }
                return(baseIterator.Current.Value);
            }

            case XPathResultType.Navigator:
                return(((XPathNavigator)obj).Value);

            default:
                throw new XPathException("invalid node type");
            }
        }
コード例 #13
0
 public static string ToString(object arg)
 {
     if (arg == null)
     {
         throw new ArgumentNullException();
     }
     if (arg is string)
     {
         return((string)arg);
     }
     if (arg is bool)
     {
         return((!(bool)arg) ? "false" : "true");
     }
     if (arg is double)
     {
         return(XPathFunctions.ToString((double)arg));
     }
     if (arg is XPathNodeIterator)
     {
         XPathNodeIterator xpathNodeIterator = (XPathNodeIterator)arg;
         if (!xpathNodeIterator.MoveNext())
         {
             return(string.Empty);
         }
         return(xpathNodeIterator.Current.Value);
     }
     else
     {
         if (arg is XPathNavigator)
         {
             return(((XPathNavigator)arg).Value);
         }
         throw new ArgumentException();
     }
 }
コード例 #14
0
        public override bool EvaluateBoolean(BaseIterator iter)
        {
            XPathResultType xpathResultType  = this._left.GetReturnType(iter);
            XPathResultType xpathResultType2 = this._right.GetReturnType(iter);

            if (xpathResultType == XPathResultType.Any)
            {
                xpathResultType = Expression.GetReturnType(this._left.Evaluate(iter));
            }
            if (xpathResultType2 == XPathResultType.Any)
            {
                xpathResultType2 = Expression.GetReturnType(this._right.Evaluate(iter));
            }
            if (xpathResultType == XPathResultType.Navigator)
            {
                xpathResultType = XPathResultType.String;
            }
            if (xpathResultType2 == XPathResultType.Navigator)
            {
                xpathResultType2 = XPathResultType.String;
            }
            if (xpathResultType == XPathResultType.NodeSet || xpathResultType2 == XPathResultType.NodeSet)
            {
                Expression expression;
                Expression expression2;
                if (xpathResultType != XPathResultType.NodeSet)
                {
                    expression  = this._right;
                    expression2 = this._left;
                    XPathResultType xpathResultType3 = xpathResultType;
                    xpathResultType2 = xpathResultType3;
                }
                else
                {
                    expression  = this._left;
                    expression2 = this._right;
                }
                if (xpathResultType2 == XPathResultType.Boolean)
                {
                    return(expression.EvaluateBoolean(iter) == expression2.EvaluateBoolean(iter) == this.trueVal);
                }
                BaseIterator baseIterator = expression.EvaluateNodeSet(iter);
                if (xpathResultType2 == XPathResultType.Number)
                {
                    double num = expression2.EvaluateNumber(iter);
                    while (baseIterator.MoveNext())
                    {
                        if (XPathFunctions.ToNumber(baseIterator.Current.Value) == num == this.trueVal)
                        {
                            return(true);
                        }
                    }
                }
                else if (xpathResultType2 == XPathResultType.String)
                {
                    string b = expression2.EvaluateString(iter);
                    while (baseIterator.MoveNext())
                    {
                        if (baseIterator.Current.Value == b == this.trueVal)
                        {
                            return(true);
                        }
                    }
                }
                else if (xpathResultType2 == XPathResultType.NodeSet)
                {
                    BaseIterator baseIterator2 = expression2.EvaluateNodeSet(iter);
                    ArrayList    arrayList     = new ArrayList();
                    while (baseIterator.MoveNext())
                    {
                        XPathNavigator xpathNavigator = baseIterator.Current;
                        arrayList.Add(XPathFunctions.ToString(xpathNavigator.Value));
                    }
                    while (baseIterator2.MoveNext())
                    {
                        XPathNavigator xpathNavigator2 = baseIterator2.Current;
                        string         a = XPathFunctions.ToString(xpathNavigator2.Value);
                        for (int i = 0; i < arrayList.Count; i++)
                        {
                            if (a == (string)arrayList[i] == this.trueVal)
                            {
                                return(true);
                            }
                        }
                    }
                }
                return(false);
            }
            else
            {
                if (xpathResultType == XPathResultType.Boolean || xpathResultType2 == XPathResultType.Boolean)
                {
                    return(this._left.EvaluateBoolean(iter) == this._right.EvaluateBoolean(iter) == this.trueVal);
                }
                if (xpathResultType == XPathResultType.Number || xpathResultType2 == XPathResultType.Number)
                {
                    return(this._left.EvaluateNumber(iter) == this._right.EvaluateNumber(iter) == this.trueVal);
                }
                return(this._left.EvaluateString(iter) == this._right.EvaluateString(iter) == this.trueVal);
            }
        }
コード例 #15
0
        public override bool EvaluateBoolean(BaseIterator iter)
        {
            XPathResultType xpathResultType  = this._left.GetReturnType(iter);
            XPathResultType xpathResultType2 = this._right.GetReturnType(iter);

            if (xpathResultType == XPathResultType.Any)
            {
                xpathResultType = Expression.GetReturnType(this._left.Evaluate(iter));
            }
            if (xpathResultType2 == XPathResultType.Any)
            {
                xpathResultType2 = Expression.GetReturnType(this._right.Evaluate(iter));
            }
            if (xpathResultType == XPathResultType.Navigator)
            {
                xpathResultType = XPathResultType.String;
            }
            if (xpathResultType2 == XPathResultType.Navigator)
            {
                xpathResultType2 = XPathResultType.String;
            }
            if (xpathResultType != XPathResultType.NodeSet && xpathResultType2 != XPathResultType.NodeSet)
            {
                return(this.Compare(this._left.EvaluateNumber(iter), this._right.EvaluateNumber(iter)));
            }
            bool       fReverse = false;
            Expression expression;
            Expression expression2;

            if (xpathResultType != XPathResultType.NodeSet)
            {
                fReverse    = true;
                expression  = this._right;
                expression2 = this._left;
                XPathResultType xpathResultType3 = xpathResultType;
                xpathResultType2 = xpathResultType3;
            }
            else
            {
                expression  = this._left;
                expression2 = this._right;
            }
            if (xpathResultType2 == XPathResultType.Boolean)
            {
                bool value  = expression.EvaluateBoolean(iter);
                bool value2 = expression2.EvaluateBoolean(iter);
                return(this.Compare(Convert.ToDouble(value), Convert.ToDouble(value2), fReverse));
            }
            BaseIterator baseIterator = expression.EvaluateNodeSet(iter);

            if (xpathResultType2 == XPathResultType.Number || xpathResultType2 == XPathResultType.String)
            {
                double arg = expression2.EvaluateNumber(iter);
                while (baseIterator.MoveNext())
                {
                    if (this.Compare(XPathFunctions.ToNumber(baseIterator.Current.Value), arg, fReverse))
                    {
                        return(true);
                    }
                }
            }
            else if (xpathResultType2 == XPathResultType.NodeSet)
            {
                BaseIterator baseIterator2 = expression2.EvaluateNodeSet(iter);
                ArrayList    arrayList     = new ArrayList();
                while (baseIterator.MoveNext())
                {
                    XPathNavigator xpathNavigator = baseIterator.Current;
                    arrayList.Add(XPathFunctions.ToNumber(xpathNavigator.Value));
                }
                while (baseIterator2.MoveNext())
                {
                    XPathNavigator xpathNavigator2 = baseIterator2.Current;
                    double         arg2            = XPathFunctions.ToNumber(xpathNavigator2.Value);
                    for (int i = 0; i < arrayList.Count; i++)
                    {
                        if (this.Compare((double)arrayList[i], arg2))
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }