// // The operand needs to use the number function // to covert to numbers internal NumericExpr(Operator.Op op, IQuery opnd1, IQuery opnd2) { if (opnd1.ReturnType() != XPathResultType.Number) { this.opnd1 = new NumberFunctions(opnd1); } else { this.opnd1 = opnd1; } if (opnd2 != null && (opnd2.ReturnType() != XPathResultType.Number)) { this.opnd2 = new NumberFunctions(opnd2); } else { this.opnd2 = opnd2; } this.op = op; }
// // The operand needs to use the number function // to covert to numbers internal NumericExpr(Operator.Op op, IQuery opnd1, IQuery opnd2) { if (opnd1.ReturnType() != XPathResultType.Number) { this.opnd1= new NumberFunctions(opnd1); } else { this.opnd1 = opnd1; } if (opnd2 != null && (opnd2.ReturnType() != XPathResultType.Number)) { this.opnd2= new NumberFunctions(opnd2); } else{ this.opnd2 = opnd2; } this.op= op; }
bool CompareAsBoolean(XPathReader reader) { object opndVar1, opndVar2; bool b1, b2; opndVar1 = this.opnd1.GetValue(reader); opndVar2 = this.opnd2.GetValue(reader); if (opnd1.ReturnType() == XPathResultType.NodeSet) { b1 = (opndVar1 != null); } else { b1 = Convert.ToBoolean(opndVar1); } if (opnd1.ReturnType() == XPathResultType.NodeSet) { b2 = (opndVar2 != null); } else { b2 = Convert.ToBoolean(opndVar2); } if (op > Operator.Op.GE) { if ((Operator.Op.EQ == op && b1 == b2) || (Operator.Op.NE == op && b1 != b2)) { return(true); } else { return(false); } } else { //need to covert the string to the number and compare the numbers. double n1 = 0, n2 = 0; try { n1 = Convert.ToDouble(b1); n2 = Convert.ToDouble(b2); } catch { return(false); } switch (op) { case Operator.Op.LT: if (n1 < n2) { return(true); } break; case Operator.Op.GT: if (n1 > n2) { return(true); } break; case Operator.Op.LE: if (n1 <= n2) { return(true); } break; case Operator.Op.GE: if (n1 >= n2) { return(true); } break; } } return(false); }