public virtual XPathSequence Evaluate(XPathSequence iter, ExprSequence args) { object [] instParams = new object [args.Count]; for (int i = 0; i < args.Count; i++) { XPathSequence val = args [i].Evaluate(iter); instParams [i] = Args [i].Type.ToRuntimeType(val); } object o = Invoke(iter, instParams); if (o == null) { return(new XPathEmptySequence(iter.Context)); } if (o is XPathSequence) { return((XPathSequence)o); } XPathItem item = o as XPathItem; if (item == null) { item = new XPathAtomicValue(o, ReturnType.SchemaType); } return(new SingleItemIterator(item, iter.Context)); }
private static bool CompareEquality(XPathAtomicValue lvalue, XPathAtomicValue rvalue) { switch (lvalue.XmlType.TypeCode) { case XmlTypeCode.Boolean: return(lvalue.ValueAsBoolean == rvalue.ValueAsBoolean); case XmlTypeCode.UntypedAtomic: case XmlTypeCode.String: return(lvalue.Value == rvalue.Value); case XmlTypeCode.Date: case XmlTypeCode.Time: case XmlTypeCode.DateTime: case XmlTypeCode.YearMonthDuration: case XmlTypeCode.DayTimeDuration: return(lvalue.ValueAsDateTime == rvalue.ValueAsDateTime); case XmlTypeCode.HexBinary: case XmlTypeCode.Base64Binary: case XmlTypeCode.AnyUri: case XmlTypeCode.QName: case XmlTypeCode.Notation: throw new NotImplementedException(); } XmlQualifiedName nameL = lvalue.XmlType.QualifiedName != XmlQualifiedName.Empty ? lvalue.XmlType.QualifiedName : new XmlQualifiedName("anyType", XmlSchema.Namespace); XmlQualifiedName nameR = rvalue.XmlType.QualifiedName != XmlQualifiedName.Empty ? rvalue.XmlType.QualifiedName : new XmlQualifiedName("anyType", XmlSchema.Namespace); throw new XmlQueryException(String.Format("Not allowed value comparison between {0} and {1}.", nameL, nameR)); }
private XmlQualifiedName EvaluateName(XPathSequence iter) { XmlQualifiedName name = Name; if (NameExpr != null) { XPathAtomicValue value = Atomize(new ExprSequenceIterator(iter, NameExpr)); IXmlNamespaceResolver res = iter.Context.NSResolver; switch (value.XmlType.TypeCode) { case XmlTypeCode.QName: name = (XmlQualifiedName)value.ValueAs(typeof(XmlQualifiedName), res); break; case XmlTypeCode.String: try { name = InternalPool.ParseQName(value.Value, res); } catch (ArgumentException ex) { // FIXME: add more info throw new XmlQueryException(String.Format("The evaluation result of the name expression could not be resolved as a valid QName. Evaluation result string is '{0}'.", value.Value)); } break; default: // FIXME: add more info throw new XmlQueryException("A name of an element constructor must be resolved to either a QName or string."); } } return(name); }
private static bool CompareEquality (XPathAtomicValue lvalue, XPathAtomicValue rvalue) { switch (lvalue.XmlType.TypeCode) { case XmlTypeCode.Boolean: return lvalue.ValueAsBoolean == rvalue.ValueAsBoolean; case XmlTypeCode.UntypedAtomic: case XmlTypeCode.String: return lvalue.Value == rvalue.Value; case XmlTypeCode.Date: case XmlTypeCode.Time: case XmlTypeCode.DateTime: case XmlTypeCode.YearMonthDuration: case XmlTypeCode.DayTimeDuration: return lvalue.ValueAsDateTime == rvalue.ValueAsDateTime; case XmlTypeCode.HexBinary: case XmlTypeCode.Base64Binary: case XmlTypeCode.AnyUri: case XmlTypeCode.QName: case XmlTypeCode.Notation: throw new NotImplementedException (); } XmlQualifiedName nameL = lvalue.XmlType.QualifiedName != XmlQualifiedName.Empty ? lvalue.XmlType.QualifiedName : new XmlQualifiedName ("anyType", XmlSchema.Namespace); XmlQualifiedName nameR = rvalue.XmlType.QualifiedName != XmlQualifiedName.Empty ? rvalue.XmlType.QualifiedName : new XmlQualifiedName ("anyType", XmlSchema.Namespace); throw new XmlQueryException (String.Format ("Not allowed value comparison between {0} and {1}.", nameL, nameR)); }
internal XPathSequence ResolveVariable(XmlQualifiedName name) { object obj = currentVariables [name]; if (obj == null && contextManager.Arguments != null) { obj = contextManager.Arguments.GetParameter(name.Name, name.Namespace); } if (obj == null) { return(new XPathEmptySequence(this)); } XPathSequence seq = obj as XPathSequence; if (seq != null) { return(seq); } XPathItem item = obj as XPathItem; if (item == null) { item = new XPathAtomicValue(obj, InternalPool.GetBuiltInType(InternalPool.XmlTypeCodeFromRuntimeType(obj.GetType(), true))); } return(new SingleItemIterator(item, this)); }
public override XPathSequence Evaluate(XPathSequence iter) { XPathSequence arg = Args [0].Evaluate(iter); if (!arg.MoveNext()) { return(new XPathEmptySequence(iter.Context)); } XPathAtomicValue a = null; // FIXME: use schema type IsDerivedFrom() switch (Type.GetTypeCode(arg.Current.ValueType)) { case TypeCode.Int64: return(new SingleItemIterator(new XPathAtomicValue(System.Math.Abs(arg.Current.ValueAsInt64), arg.Current.XmlType), iter)); case TypeCode.Int32: return(new SingleItemIterator(new XPathAtomicValue(System.Math.Abs(arg.Current.ValueAsInt32), arg.Current.XmlType), iter)); case TypeCode.Double: return(new SingleItemIterator(new XPathAtomicValue(System.Math.Abs(arg.Current.ValueAsDouble), arg.Current.XmlType), iter)); case TypeCode.Decimal: return(new SingleItemIterator(new XPathAtomicValue(System.Math.Abs(arg.Current.ValueAsDecimal), arg.Current.XmlType), iter)); case TypeCode.Single: return(new SingleItemIterator(new XPathAtomicValue(System.Math.Abs(arg.Current.ValueAsSingle), arg.Current.XmlType), iter)); } return(new XPathEmptySequence(iter.Context)); }
public static bool ValueEQ (XPathAtomicValue lvalue, XPathAtomicValue rvalue) { if (lvalue.XmlType.TypeCode == XmlTypeCode.Decimal && rvalue.XmlType.TypeCode == XmlTypeCode.Decimal) return lvalue.ValueAsDecimal == rvalue.ValueAsDecimal; if (SequenceType.IsNumeric (lvalue.XmlType.TypeCode) && SequenceType.IsNumeric (lvalue.XmlType.TypeCode)) return lvalue.ValueAsDouble == rvalue.ValueAsDouble; if (lvalue.XmlType.TypeCode == rvalue.XmlType.TypeCode) return CompareEquality (lvalue, rvalue); throw new XmlQueryException (String.Format ("Not allowed value comparison between {0} and {1}.", lvalue.XmlType.QualifiedName, rvalue.XmlType.QualifiedName)); }
private static bool FnDeepEqualItem(XPathItem i1, XPathItem i2, CultureInfo collation) { XPathAtomicValue av1 = i1 as XPathAtomicValue; XPathAtomicValue av2 = i1 as XPathAtomicValue; if (av1 != null && av2 != null) { try { return(XQueryComparisonOperator.ValueEQ(av1, av2)); } catch (XmlQueryException) { // not-allowed comparison never raises // an error here, just return false. return(false); } } else if (av1 != null || av2 != null) { return(false); } XPathNavigator n1 = i1 as XPathNavigator; XPathNavigator n2 = i2 as XPathNavigator; if (n1.NodeType != n2.NodeType) { return(false); } switch (n1.NodeType) { case XPathNodeType.Root: throw new NotImplementedException(); case XPathNodeType.Element: throw new NotImplementedException(); case XPathNodeType.Attribute: return(n1.Name == n2.Name && n1.TypedValue == n2.TypedValue); case XPathNodeType.ProcessingInstruction: case XPathNodeType.Namespace: return(n1.Name == n2.Name && n1.Value == n2.Value); case XPathNodeType.Text: case XPathNodeType.Comment: return(n1.Value == n2.Value); } return(false); }
public static bool ValueEQ(XPathAtomicValue lvalue, XPathAtomicValue rvalue) { if (lvalue.XmlType.TypeCode == XmlTypeCode.Decimal && rvalue.XmlType.TypeCode == XmlTypeCode.Decimal) { return(lvalue.ValueAsDecimal == rvalue.ValueAsDecimal); } if (SequenceType.IsNumeric(lvalue.XmlType.TypeCode) && SequenceType.IsNumeric(lvalue.XmlType.TypeCode)) { return(lvalue.ValueAsDouble == rvalue.ValueAsDouble); } if (lvalue.XmlType.TypeCode == rvalue.XmlType.TypeCode) { return(CompareEquality(lvalue, rvalue)); } throw new XmlQueryException(String.Format("Not allowed value comparison between {0} and {1}.", lvalue.XmlType.QualifiedName, rvalue.XmlType.QualifiedName)); }
private static bool CompareGE(XPathAtomicValue lvalue, XPathAtomicValue rvalue) { switch (lvalue.XmlType.TypeCode) { case XmlTypeCode.Boolean: return(!OpBooleanLessThan(lvalue.ValueAsBoolean, rvalue.ValueAsBoolean)); case XmlTypeCode.String: return(lvalue.Value == rvalue.Value); case XmlTypeCode.Date: case XmlTypeCode.Time: case XmlTypeCode.DateTime: case XmlTypeCode.YearMonthDuration: case XmlTypeCode.DayTimeDuration: return(lvalue.ValueAsDateTime >= rvalue.ValueAsDateTime); } throw new XmlQueryException(String.Format("Not allowed value comparison between {0} and {1}.", lvalue.XmlType.QualifiedName, rvalue.XmlType.QualifiedName)); }
public static object FnTrace(XQueryContext ctx, object value, string label) { if (value == null) { return(new XPathEmptySequence(ctx)); } XPathSequence seq = value as XPathSequence; if (seq == null) { XPathAtomicValue av = value as XPathAtomicValue; if (av == null) { av = new XPathAtomicValue(value, InternalPool.GetBuiltInType( InternalPool.XmlTypeCodeFromRuntimeType( value.GetType(), true))); } seq = new SingleItemIterator(av, ctx); } return(new TracingIterator(seq, label)); }
public void BooleanType () { XmlSchemaType xstype = XmlSchemaType.GetBuiltInSimpleType (XmlTypeCode.Boolean); XPathAtomicValue av; // true av = new XPathAtomicValue (true, xstype); AssertAtomicValue (av, false, typeof (bool), // ValueType xstype, // XmlType true, // TypedValue typeof (bool), // actual Type of TypedValue "true", // string true, // bool null, // DateTime (decimal) 1, // decimal 1.0, // double 1, // int32 1, // int64 (float) 1.0, // single 1); // array count // false av = new XPathAtomicValue (false, xstype); AssertAtomicValue (av, false, typeof (bool), // ValueType xstype, // XmlType false, // TypedValue typeof (bool), // actual Type of TypedValue "false", // string false, // bool null, // DateTime (decimal) 0, // decimal 0.0, // double 0, // int32 0, // int64 (float) 0.0, // single 1); // array count // 0 av = new XPathAtomicValue (false, xstype); AssertAtomicValue (av, false, typeof (bool), // ValueType xstype, // XmlType false, // TypedValue typeof (bool), // actual Type of TypedValue "false", // string false, // bool null, // DateTime (decimal) 0, // decimal 0.0, // double 0, // int32 0, // int64 (float) 0.0, // single 1); // array count // 5 av = new XPathAtomicValue (5, xstype); AssertAtomicValue (av, false, typeof (bool), // ValueType xstype, // XmlType true, // TypedValue typeof (bool), // actual Type of TypedValue "true", // string true, // bool null, // DateTime (decimal) 5, // decimal 5.0, // double 5, // int32 5, // int64 (float) 5.0, // single 1); // array count // short short shortValue = 3; av = new XPathAtomicValue (shortValue, xstype); AssertAtomicValue (av, false, typeof (bool), // ValueType xstype, // XmlType true, // TypedValue typeof (bool), // actual Type of TypedValue "true", // string true, // bool null, // DateTime (decimal) 3, // decimal 3.0, // double 3, // int32 3, // int64 (float) 3.0, // single 1); // array count // "1" av = new XPathAtomicValue ("1", xstype); AssertAtomicValue (av, false, typeof (bool), // ValueType xstype, // XmlType true, // TypedValue typeof (bool), // actual Type of TypedValue "true", // string true, // bool null, // DateTime (decimal) 1, // decimal 1.0, // double 1, // int32 1, // int64 (float) 1.0, // single 1); // array count // new bool [] {true} av = new XPathAtomicValue (new bool [] {true}, xstype); AssertAtomicValue (av, false, typeof (bool), // ValueType xstype, // XmlType true, // TypedValue typeof (bool), // actual Type of TypedValue "true", // string true, // bool null, // DateTime (decimal) 1, // decimal 1.0, // double 1, // int32 1, // int64 (float) 1.0, // single 1); // array count // new ArrayList (new int [] {6}) av = new XPathAtomicValue (new ArrayList (new int [] {6}), xstype); AssertAtomicValue (av, false, typeof (bool), // ValueType xstype, // XmlType true, // TypedValue typeof (bool), // actual Type of TypedValue "true", // string true, // bool null, // DateTime (decimal) 6, // decimal 6.0, // double 6, // int32 6, // int64 (float) 6.0, // single 1); // array count // Hashtable, [7] = 7 Hashtable ht = new Hashtable (); ht [7] = 7; av = new XPathAtomicValue (ht, xstype); AssertAtomicValue (av, false, typeof (bool), // ValueType xstype, // XmlType true, // TypedValue typeof (bool), // actual Type of TypedValue "true", // string true, // bool null, // DateTime (decimal) 7, // decimal 7.0, // double 7, // int32 7, // int64 (float) 7.0, // single 1); // array count // - MS.NET will fail here due to its bug - // another XPathAtomicValue that is bool av = new XPathAtomicValue (true, xstype); av = new XPathAtomicValue (av, xstype); AssertAtomicValue (av, false, typeof (bool), // ValueType xstype, // XmlType true, // TypedValue typeof (bool), // actual Type of TypedValue "true", // string true, // bool null, // DateTime (decimal) 1, // decimal 1.0, // double 1, // int32 1, // int64 (float) 1.0, // single 1); // array count // Array, [0] = XPathAtomicValue av = new XPathAtomicValue (new XPathAtomicValue [] {av}, xstype); AssertAtomicValue (av, false, typeof (bool), // ValueType xstype, // XmlType true, // TypedValue typeof (bool), // actual Type of TypedValue "true", // string true, // bool null, // DateTime (decimal) 1, // decimal 1.0, // double 1, // int32 1, // int64 (float) 1.0, // single 1); // array count // new bool [] {true, false} av = new XPathAtomicValue (new bool [] {true, false}, xstype); try { object o = av.ValueAsBoolean; Assert.Fail ("ArrayList must contain just one item to be castable to bool"); } catch (InvalidCastException) { } // empty ArrayList av = new XPathAtomicValue (new ArrayList (), xstype); try { object o = av.ValueAsBoolean; Assert.Fail ("ArrayList must contain just one item to be castable to bool"); } catch (InvalidCastException) { } // "True" av = new XPathAtomicValue ("True", xstype); try { object o = av.ValueAsBoolean; Assert.Fail ("\"True\" is not a boolean representation (\"true\" is)."); } catch (InvalidCastException) { } // DateTime av = new XPathAtomicValue (DateTime.Now, xstype); try { object o = av.ValueAsBoolean; Assert.Fail ("DateTime should not be castable to bool."); } catch (InvalidCastException) { } // XmlText node that contains boolean representation value XmlDocument doc = new XmlDocument (); doc.LoadXml ("<root>true</root>"); XmlNode node = doc.DocumentElement.FirstChild; av = new XPathAtomicValue (node, xstype); try { object o = av.ValueAsBoolean; Assert.Fail ("XmlText cannot be castable to bool."); } catch (InvalidCastException) { } // XPathNavigator whose node points to text node whose // value represents boolean string. av = new XPathAtomicValue (node.CreateNavigator (), xstype); try { object o = av.ValueAsBoolean; Assert.Fail ("XmlText cannot be castable to bool."); } catch (InvalidCastException) { } }
public void AssertAtomicValue (XPathAtomicValue av, bool isNode, Type valueType, XmlSchemaType xmlType, object typedValue, Type typedValueType, string value, object boolValue, object dateValue, object decimalValue, object doubleValue, object int32Value, object int64Value, object singleValue, int listCount) { Assert.AreEqual (isNode, av.IsNode, "IsNode"); Assert.AreEqual (valueType, av.ValueType, "ValueType"); Assert.AreEqual (xmlType, av.XmlType, "XmlType"); Assert.AreEqual (typedValue, av.TypedValue, "TypedValue"); Assert.AreEqual (typedValueType, typedValue.GetType (), "typedValue.GetType()"); if (value != null) Assert.AreEqual (value, av.Value, "Value"); else { try { value = av.Value; Assert.Fail ("not supported conversion to String."); } catch (InvalidCastException) { } } // FIXME: Failure cases could not be tested; // any kind of Exceptions are thrown as yet. if (boolValue != null) Assert.AreEqual (boolValue, av.ValueAsBoolean, "ValueAsBoolean"); /* else { try { boolValue = av.ValueAsBoolean; Assert.Fail ("not supported conversion to Boolean."); } catch (InvalidCastException) { } } */ if (dateValue != null) Assert.AreEqual (dateValue, av.ValueAsDateTime, "ValueAsDateTime"); /* else { try { dateValue = av.ValueAsDateTime; Assert.Fail ("not supported conversion to DateTime."); } catch (InvalidCastException) { } } */ if (decimalValue != null) Assert.AreEqual (decimalValue, av.ValueAsDecimal, "ValueAsDecimal"); /* else { try { decimalValue = av.ValueAsDecimal; Assert.Fail ("not supported conversion to Decimal."); } catch (InvalidCastException) { } } */ if (doubleValue != null) Assert.AreEqual (doubleValue, av.ValueAsDouble, "ValueAsDouble"); /* else { try { doubleValue = av.ValueAsDouble; Assert.Fail ("not supported conversion to Double."); } catch (InvalidCastException) { } } */ if (int32Value != null) Assert.AreEqual (int32Value, av.ValueAsInt32, "ValueAsInt32"); /* else { try { int32Value = av.ValueAsInt32; Assert.Fail ("not supported conversion to Int32."); } catch (InvalidCastException) { } } */ if (int64Value != null) Assert.AreEqual (int64Value, av.ValueAsInt64, "ValueAsInt64"); /* else { try { int64Value = av.ValueAsInt64; Assert.Fail ("not supported conversion to Int64."); } catch (InvalidCastException) { } } */ if (singleValue != null) Assert.AreEqual (singleValue, av.ValueAsSingle, "ValueAsSingle"); /* else { try { singleValue = av.ValueAsSingle; Assert.Fail ("not supported conversion to Single."); } catch (InvalidCastException) { } } */ Assert.AreEqual (listCount, av.ValueAsList.Count, "ValueAsList.Count"); }
private static bool CompareGE (XPathAtomicValue lvalue, XPathAtomicValue rvalue) { switch (lvalue.XmlType.TypeCode) { case XmlTypeCode.Boolean: return !OpBooleanLessThan (lvalue.ValueAsBoolean, rvalue.ValueAsBoolean); case XmlTypeCode.String: return lvalue.Value == rvalue.Value; case XmlTypeCode.Date: case XmlTypeCode.Time: case XmlTypeCode.DateTime: case XmlTypeCode.YearMonthDuration: case XmlTypeCode.DayTimeDuration: return lvalue.ValueAsDateTime >= rvalue.ValueAsDateTime; } throw new XmlQueryException (String.Format ("Not allowed value comparison between {0} and {1}.", lvalue.XmlType.QualifiedName, rvalue.XmlType.QualifiedName)); }
public void AssertAtomicValue(XPathAtomicValue av, bool isNode, Type valueType, XmlSchemaType xmlType, object typedValue, Type typedValueType, string value, object boolValue, object dateValue, object decimalValue, object doubleValue, object int32Value, object int64Value, object singleValue, int listCount) { Assert.AreEqual(isNode, av.IsNode, "IsNode"); Assert.AreEqual(valueType, av.ValueType, "ValueType"); Assert.AreEqual(xmlType, av.XmlType, "XmlType"); Assert.AreEqual(typedValue, av.TypedValue, "TypedValue"); Assert.AreEqual(typedValueType, typedValue.GetType(), "typedValue.GetType()"); if (value != null) { Assert.AreEqual(value, av.Value, "Value"); } else { try { value = av.Value; Assert.Fail("not supported conversion to String."); } catch (InvalidCastException) { } } // FIXME: Failure cases could not be tested; // any kind of Exceptions are thrown as yet. if (boolValue != null) { Assert.AreEqual(boolValue, av.ValueAsBoolean, "ValueAsBoolean"); } /* * else { * try { * boolValue = av.ValueAsBoolean; * Assert.Fail ("not supported conversion to Boolean."); * } catch (InvalidCastException) { * } * } */ if (dateValue != null) { Assert.AreEqual(dateValue, av.ValueAsDateTime, "ValueAsDateTime"); } /* * else { * try { * dateValue = av.ValueAsDateTime; * Assert.Fail ("not supported conversion to DateTime."); * } catch (InvalidCastException) { * } * } */ if (decimalValue != null) { Assert.AreEqual(decimalValue, av.ValueAsDecimal, "ValueAsDecimal"); } /* * else { * try { * decimalValue = av.ValueAsDecimal; * Assert.Fail ("not supported conversion to Decimal."); * } catch (InvalidCastException) { * } * } */ if (doubleValue != null) { Assert.AreEqual(doubleValue, av.ValueAsDouble, "ValueAsDouble"); } /* * else { * try { * doubleValue = av.ValueAsDouble; * Assert.Fail ("not supported conversion to Double."); * } catch (InvalidCastException) { * } * } */ if (int32Value != null) { Assert.AreEqual(int32Value, av.ValueAsInt32, "ValueAsInt32"); } /* * else { * try { * int32Value = av.ValueAsInt32; * Assert.Fail ("not supported conversion to Int32."); * } catch (InvalidCastException) { * } * } */ if (int64Value != null) { Assert.AreEqual(int64Value, av.ValueAsInt64, "ValueAsInt64"); } /* * else { * try { * int64Value = av.ValueAsInt64; * Assert.Fail ("not supported conversion to Int64."); * } catch (InvalidCastException) { * } * } */ if (singleValue != null) { Assert.AreEqual(singleValue, av.ValueAsSingle, "ValueAsSingle"); } /* * else { * try { * singleValue = av.ValueAsSingle; * Assert.Fail ("not supported conversion to Single."); * } catch (InvalidCastException) { * } * } */ Assert.AreEqual(listCount, av.ValueAsList.Count, "ValueAsList.Count"); }
/// <summary> /// x imod y /// </summary> public static XPathAtomicValue Remainder(XPathAtomicValue lvalue, XPathAtomicValue rvalue) { return(new XPathAtomicValue(lvalue.ValueAsInt64 % rvalue.ValueAsInt64, InternalPool.XsInteger)); }
/// <summary> /// x / y /// </summary> public static XPathAtomicValue Divide(XPathAtomicValue lvalue, XPathAtomicValue rvalue) { // numeric, date, time, dateTime, yearMonthDuration, dayTimeDuration switch (lvalue.XmlType.TypeCode) { // numerics case XmlTypeCode.Integer: switch (rvalue.XmlType.TypeCode) { case XmlTypeCode.Integer: return(new XPathAtomicValue(lvalue.ValueAsInt64 / rvalue.ValueAsInt64, rvalue.XmlType)); case XmlTypeCode.Decimal: return(new XPathAtomicValue(lvalue.ValueAsDecimal / rvalue.ValueAsDecimal, rvalue.XmlType)); case XmlTypeCode.Float: case XmlTypeCode.Double: return(new XPathAtomicValue(lvalue.ValueAsDouble / rvalue.ValueAsDouble, rvalue.XmlType)); } break; case XmlTypeCode.Decimal: switch (rvalue.XmlType.TypeCode) { case XmlTypeCode.Integer: case XmlTypeCode.Decimal: return(new XPathAtomicValue(lvalue.ValueAsDecimal / rvalue.ValueAsDecimal, rvalue.XmlType)); case XmlTypeCode.Float: case XmlTypeCode.Double: return(new XPathAtomicValue(lvalue.ValueAsDouble / rvalue.ValueAsDouble, rvalue.XmlType)); } break; case XmlTypeCode.Float: case XmlTypeCode.Double: switch (rvalue.XmlType.TypeCode) { case XmlTypeCode.Integer: case XmlTypeCode.Decimal: case XmlTypeCode.Float: case XmlTypeCode.Double: return(new XPathAtomicValue(lvalue.ValueAsDouble / rvalue.ValueAsDouble, rvalue.XmlType)); case XmlTypeCode.DayTimeDuration: case XmlTypeCode.YearMonthDuration: goto case XmlTypeCode.Decimal; } break; // durations case XmlTypeCode.DayTimeDuration: case XmlTypeCode.YearMonthDuration: switch (rvalue.XmlType.TypeCode) { case XmlTypeCode.Integer: case XmlTypeCode.Decimal: case XmlTypeCode.Float: case XmlTypeCode.Double: return(new XPathAtomicValue(new DateTime((long)(lvalue.ValueAsDateTime.Ticks / rvalue.ValueAsDouble)), rvalue.XmlType)); } break; } throw new XmlQueryException(String.Format("Not allowed arithmetic operation: {0} div {1}", lvalue.XmlType.QualifiedName, rvalue.XmlType.QualifiedName)); }
public virtual XPathSequence Evaluate (XPathSequence iter, ExprSequence args) { object [] instParams = new object [args.Count]; for (int i = 0; i < args.Count; i++) { XPathSequence val = args [i].Evaluate (iter); instParams [i] = Args [i].Type.ToRuntimeType (val); } object o = Invoke (iter, instParams); if (o == null) return new XPathEmptySequence (iter.Context); if (o is XPathSequence) return (XPathSequence) o; XPathItem item = o as XPathItem; if (item == null) item = new XPathAtomicValue (o, ReturnType.SchemaType); return new SingleItemIterator (item, iter.Context); }
public void BooleanType() { XmlSchemaType xstype = XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.Boolean); XPathAtomicValue av; // true av = new XPathAtomicValue(true, xstype); AssertAtomicValue(av, false, typeof(bool), // ValueType xstype, // XmlType true, // TypedValue typeof(bool), // actual Type of TypedValue "true", // string true, // bool null, // DateTime (decimal)1, // decimal 1.0, // double 1, // int32 1, // int64 (float)1.0, // single 1); // array count // false av = new XPathAtomicValue(false, xstype); AssertAtomicValue(av, false, typeof(bool), // ValueType xstype, // XmlType false, // TypedValue typeof(bool), // actual Type of TypedValue "false", // string false, // bool null, // DateTime (decimal)0, // decimal 0.0, // double 0, // int32 0, // int64 (float)0.0, // single 1); // array count // 0 av = new XPathAtomicValue(false, xstype); AssertAtomicValue(av, false, typeof(bool), // ValueType xstype, // XmlType false, // TypedValue typeof(bool), // actual Type of TypedValue "false", // string false, // bool null, // DateTime (decimal)0, // decimal 0.0, // double 0, // int32 0, // int64 (float)0.0, // single 1); // array count // 5 av = new XPathAtomicValue(5, xstype); AssertAtomicValue(av, false, typeof(bool), // ValueType xstype, // XmlType true, // TypedValue typeof(bool), // actual Type of TypedValue "true", // string true, // bool null, // DateTime (decimal)5, // decimal 5.0, // double 5, // int32 5, // int64 (float)5.0, // single 1); // array count // short short shortValue = 3; av = new XPathAtomicValue(shortValue, xstype); AssertAtomicValue(av, false, typeof(bool), // ValueType xstype, // XmlType true, // TypedValue typeof(bool), // actual Type of TypedValue "true", // string true, // bool null, // DateTime (decimal)3, // decimal 3.0, // double 3, // int32 3, // int64 (float)3.0, // single 1); // array count // "1" av = new XPathAtomicValue("1", xstype); AssertAtomicValue(av, false, typeof(bool), // ValueType xstype, // XmlType true, // TypedValue typeof(bool), // actual Type of TypedValue "true", // string true, // bool null, // DateTime (decimal)1, // decimal 1.0, // double 1, // int32 1, // int64 (float)1.0, // single 1); // array count // new bool [] {true} av = new XPathAtomicValue(new bool [] { true }, xstype); AssertAtomicValue(av, false, typeof(bool), // ValueType xstype, // XmlType true, // TypedValue typeof(bool), // actual Type of TypedValue "true", // string true, // bool null, // DateTime (decimal)1, // decimal 1.0, // double 1, // int32 1, // int64 (float)1.0, // single 1); // array count // new ArrayList (new int [] {6}) av = new XPathAtomicValue(new ArrayList(new int [] { 6 }), xstype); AssertAtomicValue(av, false, typeof(bool), // ValueType xstype, // XmlType true, // TypedValue typeof(bool), // actual Type of TypedValue "true", // string true, // bool null, // DateTime (decimal)6, // decimal 6.0, // double 6, // int32 6, // int64 (float)6.0, // single 1); // array count // Hashtable, [7] = 7 Hashtable ht = new Hashtable(); ht [7] = 7; av = new XPathAtomicValue(ht, xstype); AssertAtomicValue(av, false, typeof(bool), // ValueType xstype, // XmlType true, // TypedValue typeof(bool), // actual Type of TypedValue "true", // string true, // bool null, // DateTime (decimal)7, // decimal 7.0, // double 7, // int32 7, // int64 (float)7.0, // single 1); // array count // - MS.NET will fail here due to its bug - // another XPathAtomicValue that is bool av = new XPathAtomicValue(true, xstype); av = new XPathAtomicValue(av, xstype); AssertAtomicValue(av, false, typeof(bool), // ValueType xstype, // XmlType true, // TypedValue typeof(bool), // actual Type of TypedValue "true", // string true, // bool null, // DateTime (decimal)1, // decimal 1.0, // double 1, // int32 1, // int64 (float)1.0, // single 1); // array count // Array, [0] = XPathAtomicValue av = new XPathAtomicValue(new XPathAtomicValue [] { av }, xstype); AssertAtomicValue(av, false, typeof(bool), // ValueType xstype, // XmlType true, // TypedValue typeof(bool), // actual Type of TypedValue "true", // string true, // bool null, // DateTime (decimal)1, // decimal 1.0, // double 1, // int32 1, // int64 (float)1.0, // single 1); // array count // new bool [] {true, false} av = new XPathAtomicValue(new bool [] { true, false }, xstype); try { object o = av.ValueAsBoolean; Assert.Fail("ArrayList must contain just one item to be castable to bool"); } catch (InvalidCastException) { } // empty ArrayList av = new XPathAtomicValue(new ArrayList(), xstype); try { object o = av.ValueAsBoolean; Assert.Fail("ArrayList must contain just one item to be castable to bool"); } catch (InvalidCastException) { } // "True" av = new XPathAtomicValue("True", xstype); try { object o = av.ValueAsBoolean; Assert.Fail("\"True\" is not a boolean representation (\"true\" is)."); } catch (InvalidCastException) { } // DateTime av = new XPathAtomicValue(DateTime.Now, xstype); try { object o = av.ValueAsBoolean; Assert.Fail("DateTime should not be castable to bool."); } catch (InvalidCastException) { } // XmlText node that contains boolean representation value XmlDocument doc = new XmlDocument(); doc.LoadXml("<root>true</root>"); XmlNode node = doc.DocumentElement.FirstChild; av = new XPathAtomicValue(node, xstype); try { object o = av.ValueAsBoolean; Assert.Fail("XmlText cannot be castable to bool."); } catch (InvalidCastException) { } // XPathNavigator whose node points to text node whose // value represents boolean string. av = new XPathAtomicValue(node.CreateNavigator(), xstype); try { object o = av.ValueAsBoolean; Assert.Fail("XmlText cannot be castable to bool."); } catch (InvalidCastException) { } }
internal XPathSequence ResolveVariable (XmlQualifiedName name) { object obj = currentVariables [name]; if (obj == null && contextManager.Arguments != null) obj = contextManager.Arguments.GetParameter (name.Name, name.Namespace); if (obj == null) return new XPathEmptySequence (this); XPathSequence seq = obj as XPathSequence; if (seq != null) return seq; XPathItem item = obj as XPathItem; if (item == null) item = new XPathAtomicValue (obj, InternalPool.GetBuiltInType (InternalPool.XmlTypeCodeFromRuntimeType (obj.GetType (), true))); return new SingleItemIterator (item, this); }
/// <summary> /// x - y /// </summary> public static XPathAtomicValue Subtract (XPathAtomicValue lvalue, XPathAtomicValue rvalue) { // numeric, date, time, dateTime, yearMonthDuration, dayTimeDuration switch (lvalue.XmlType.TypeCode) { // numerics case XmlTypeCode.Integer: switch (rvalue.XmlType.TypeCode) { case XmlTypeCode.Integer: return new XPathAtomicValue (lvalue.ValueAsInt64 - rvalue.ValueAsInt64, rvalue.XmlType); case XmlTypeCode.Decimal: return new XPathAtomicValue (lvalue.ValueAsDecimal - rvalue.ValueAsDecimal, rvalue.XmlType); case XmlTypeCode.Float: case XmlTypeCode.Double: return new XPathAtomicValue (lvalue.ValueAsDouble - rvalue.ValueAsDouble, rvalue.XmlType); } break; case XmlTypeCode.Decimal: switch (rvalue.XmlType.TypeCode) { case XmlTypeCode.Integer: case XmlTypeCode.Decimal: return new XPathAtomicValue (lvalue.ValueAsDecimal - rvalue.ValueAsDecimal, rvalue.XmlType); case XmlTypeCode.Float: case XmlTypeCode.Double: return new XPathAtomicValue (lvalue.ValueAsDouble - rvalue.ValueAsDouble, rvalue.XmlType); } break; case XmlTypeCode.Float: case XmlTypeCode.Double: switch (rvalue.XmlType.TypeCode) { case XmlTypeCode.Integer: case XmlTypeCode.Decimal: case XmlTypeCode.Float: case XmlTypeCode.Double: return new XPathAtomicValue (lvalue.ValueAsDouble - rvalue.ValueAsDouble, rvalue.XmlType); } break; // datetimes case XmlTypeCode.Time: switch (rvalue.XmlType.TypeCode) { case XmlTypeCode.Time: return new XPathAtomicValue (lvalue.ValueAsDateTime - rvalue.ValueAsDateTime, InternalPool.XdtDayTimeDuration); case XmlTypeCode.DayTimeDuration: return new XPathAtomicValue (lvalue.ValueAsDateTime - new TimeSpan (rvalue.ValueAsDateTime.Ticks), lvalue.XmlType); } break; case XmlTypeCode.DateTime: switch (rvalue.XmlType.TypeCode) { case XmlTypeCode.DateTime: // FIXME: check fn:subtract-daytimes-yielding-dayTimeDuration() return new XPathAtomicValue (lvalue.ValueAsDateTime - rvalue.ValueAsDateTime, InternalPool.XdtDayTimeDuration); case XmlTypeCode.YearMonthDuration: case XmlTypeCode.DayTimeDuration: return new XPathAtomicValue (lvalue.ValueAsDateTime - new TimeSpan (rvalue.ValueAsDateTime.Ticks), lvalue.XmlType); } break; case XmlTypeCode.Date: switch (rvalue.XmlType.TypeCode) { case XmlTypeCode.Date: // FIXME: check fn:subtract-daytimes-yielding-dayTimeDuration() return new XPathAtomicValue (lvalue.ValueAsDateTime - rvalue.ValueAsDateTime, InternalPool.XdtDayTimeDuration); case XmlTypeCode.YearMonthDuration: case XmlTypeCode.DayTimeDuration: return new XPathAtomicValue (lvalue.ValueAsDateTime - new TimeSpan (rvalue.ValueAsDateTime.Ticks), lvalue.XmlType); } break; // durations case XmlTypeCode.YearMonthDuration: if (rvalue.XmlType.TypeCode == XmlTypeCode.YearMonthDuration) return new XPathAtomicValue (new TimeSpan (lvalue.ValueAsDateTime.Ticks - rvalue.ValueAsDateTime.Ticks), InternalPool.XdtYearMonthDuration); break; case XmlTypeCode.DayTimeDuration: if (rvalue.XmlType.TypeCode == XmlTypeCode.DayTimeDuration) return new XPathAtomicValue (new TimeSpan (lvalue.ValueAsDateTime.Ticks - rvalue.ValueAsDateTime.Ticks), InternalPool.XdtDayTimeDuration); break; } throw new XmlQueryException (String.Format ("Not allowed arithmetic operation: {0} - {1}", lvalue.XmlType.QualifiedName, rvalue.XmlType.QualifiedName)); }
/// <summary> /// x / y /// </summary> public static XPathAtomicValue Divide (XPathAtomicValue lvalue, XPathAtomicValue rvalue) { // numeric, date, time, dateTime, yearMonthDuration, dayTimeDuration switch (lvalue.XmlType.TypeCode) { // numerics case XmlTypeCode.Integer: switch (rvalue.XmlType.TypeCode) { case XmlTypeCode.Integer: return new XPathAtomicValue (lvalue.ValueAsInt64 / rvalue.ValueAsInt64, rvalue.XmlType); case XmlTypeCode.Decimal: return new XPathAtomicValue (lvalue.ValueAsDecimal / rvalue.ValueAsDecimal, rvalue.XmlType); case XmlTypeCode.Float: case XmlTypeCode.Double: return new XPathAtomicValue (lvalue.ValueAsDouble / rvalue.ValueAsDouble, rvalue.XmlType); } break; case XmlTypeCode.Decimal: switch (rvalue.XmlType.TypeCode) { case XmlTypeCode.Integer: case XmlTypeCode.Decimal: return new XPathAtomicValue (lvalue.ValueAsDecimal / rvalue.ValueAsDecimal, rvalue.XmlType); case XmlTypeCode.Float: case XmlTypeCode.Double: return new XPathAtomicValue (lvalue.ValueAsDouble / rvalue.ValueAsDouble, rvalue.XmlType); } break; case XmlTypeCode.Float: case XmlTypeCode.Double: switch (rvalue.XmlType.TypeCode) { case XmlTypeCode.Integer: case XmlTypeCode.Decimal: case XmlTypeCode.Float: case XmlTypeCode.Double: return new XPathAtomicValue (lvalue.ValueAsDouble / rvalue.ValueAsDouble, rvalue.XmlType); case XmlTypeCode.DayTimeDuration: case XmlTypeCode.YearMonthDuration: goto case XmlTypeCode.Decimal; } break; // durations case XmlTypeCode.DayTimeDuration: case XmlTypeCode.YearMonthDuration: switch (rvalue.XmlType.TypeCode) { case XmlTypeCode.Integer: case XmlTypeCode.Decimal: case XmlTypeCode.Float: case XmlTypeCode.Double: return new XPathAtomicValue (new DateTime ((long) (lvalue.ValueAsDateTime.Ticks / rvalue.ValueAsDouble)), rvalue.XmlType); } break; } throw new XmlQueryException (String.Format ("Not allowed arithmetic operation: {0} div {1}", lvalue.XmlType.QualifiedName, rvalue.XmlType.QualifiedName)); }
/// <summary> /// x - y /// </summary> public static XPathAtomicValue Subtract(XPathAtomicValue lvalue, XPathAtomicValue rvalue) { // numeric, date, time, dateTime, yearMonthDuration, dayTimeDuration switch (lvalue.XmlType.TypeCode) { // numerics case XmlTypeCode.Integer: switch (rvalue.XmlType.TypeCode) { case XmlTypeCode.Integer: return(new XPathAtomicValue(lvalue.ValueAsInt64 - rvalue.ValueAsInt64, rvalue.XmlType)); case XmlTypeCode.Decimal: return(new XPathAtomicValue(lvalue.ValueAsDecimal - rvalue.ValueAsDecimal, rvalue.XmlType)); case XmlTypeCode.Float: case XmlTypeCode.Double: return(new XPathAtomicValue(lvalue.ValueAsDouble - rvalue.ValueAsDouble, rvalue.XmlType)); } break; case XmlTypeCode.Decimal: switch (rvalue.XmlType.TypeCode) { case XmlTypeCode.Integer: case XmlTypeCode.Decimal: return(new XPathAtomicValue(lvalue.ValueAsDecimal - rvalue.ValueAsDecimal, rvalue.XmlType)); case XmlTypeCode.Float: case XmlTypeCode.Double: return(new XPathAtomicValue(lvalue.ValueAsDouble - rvalue.ValueAsDouble, rvalue.XmlType)); } break; case XmlTypeCode.Float: case XmlTypeCode.Double: switch (rvalue.XmlType.TypeCode) { case XmlTypeCode.Integer: case XmlTypeCode.Decimal: case XmlTypeCode.Float: case XmlTypeCode.Double: return(new XPathAtomicValue(lvalue.ValueAsDouble - rvalue.ValueAsDouble, rvalue.XmlType)); } break; // datetimes case XmlTypeCode.Time: switch (rvalue.XmlType.TypeCode) { case XmlTypeCode.Time: return(new XPathAtomicValue(lvalue.ValueAsDateTime - rvalue.ValueAsDateTime, InternalPool.XdtDayTimeDuration)); case XmlTypeCode.DayTimeDuration: return(new XPathAtomicValue(lvalue.ValueAsDateTime - new TimeSpan(rvalue.ValueAsDateTime.Ticks), lvalue.XmlType)); } break; case XmlTypeCode.DateTime: switch (rvalue.XmlType.TypeCode) { case XmlTypeCode.DateTime: // FIXME: check fn:subtract-daytimes-yielding-dayTimeDuration() return(new XPathAtomicValue(lvalue.ValueAsDateTime - rvalue.ValueAsDateTime, InternalPool.XdtDayTimeDuration)); case XmlTypeCode.YearMonthDuration: case XmlTypeCode.DayTimeDuration: return(new XPathAtomicValue(lvalue.ValueAsDateTime - new TimeSpan(rvalue.ValueAsDateTime.Ticks), lvalue.XmlType)); } break; case XmlTypeCode.Date: switch (rvalue.XmlType.TypeCode) { case XmlTypeCode.Date: // FIXME: check fn:subtract-daytimes-yielding-dayTimeDuration() return(new XPathAtomicValue(lvalue.ValueAsDateTime - rvalue.ValueAsDateTime, InternalPool.XdtDayTimeDuration)); case XmlTypeCode.YearMonthDuration: case XmlTypeCode.DayTimeDuration: return(new XPathAtomicValue(lvalue.ValueAsDateTime - new TimeSpan(rvalue.ValueAsDateTime.Ticks), lvalue.XmlType)); } break; // durations case XmlTypeCode.YearMonthDuration: if (rvalue.XmlType.TypeCode == XmlTypeCode.YearMonthDuration) { return(new XPathAtomicValue(new TimeSpan(lvalue.ValueAsDateTime.Ticks - rvalue.ValueAsDateTime.Ticks), InternalPool.XdtYearMonthDuration)); } break; case XmlTypeCode.DayTimeDuration: if (rvalue.XmlType.TypeCode == XmlTypeCode.DayTimeDuration) { return(new XPathAtomicValue(new TimeSpan(lvalue.ValueAsDateTime.Ticks - rvalue.ValueAsDateTime.Ticks), InternalPool.XdtDayTimeDuration)); } break; } throw new XmlQueryException(String.Format("Not allowed arithmetic operation: {0} - {1}", lvalue.XmlType.QualifiedName, rvalue.XmlType.QualifiedName)); }
/// <summary> /// x idiv y /// </summary> public static XPathAtomicValue IntDivide (XPathAtomicValue lvalue, XPathAtomicValue rvalue) { return new XPathAtomicValue (lvalue.ValueAsInt64 / rvalue.ValueAsInt64, InternalPool.XsInteger); }
/// <summary> /// x idiv y /// </summary> public static XPathAtomicValue IntDivide(XPathAtomicValue lvalue, XPathAtomicValue rvalue) { return(new XPathAtomicValue(lvalue.ValueAsInt64 / rvalue.ValueAsInt64, InternalPool.XsInteger)); }
/// <summary> /// x imod y /// </summary> public static XPathAtomicValue Remainder (XPathAtomicValue lvalue, XPathAtomicValue rvalue) { return new XPathAtomicValue (lvalue.ValueAsInt64 % rvalue.ValueAsInt64, InternalPool.XsInteger); }
/// <summary> /// x + y /// </summary> public static XPathAtomicValue Add(XPathAtomicValue lvalue, XPathAtomicValue rvalue) { // numeric, date, time, dateTime, yearMonthDuration, dayTimeDuration switch (lvalue.XmlType.TypeCode) { // numerics case XmlTypeCode.Integer: switch (rvalue.XmlType.TypeCode) { case XmlTypeCode.Integer: return(new XPathAtomicValue(lvalue.ValueAsInt64 + rvalue.ValueAsInt64, rvalue.XmlType)); case XmlTypeCode.Decimal: return(new XPathAtomicValue(lvalue.ValueAsDecimal + rvalue.ValueAsDecimal, rvalue.XmlType)); case XmlTypeCode.Float: case XmlTypeCode.Double: return(new XPathAtomicValue(lvalue.ValueAsDouble + rvalue.ValueAsDouble, rvalue.XmlType)); } break; case XmlTypeCode.Decimal: switch (rvalue.XmlType.TypeCode) { case XmlTypeCode.Integer: case XmlTypeCode.Decimal: return(new XPathAtomicValue(lvalue.ValueAsDecimal + rvalue.ValueAsDecimal, rvalue.XmlType)); case XmlTypeCode.Float: case XmlTypeCode.Double: return(new XPathAtomicValue(lvalue.ValueAsDouble + rvalue.ValueAsDouble, rvalue.XmlType)); } break; case XmlTypeCode.Float: case XmlTypeCode.Double: switch (rvalue.XmlType.TypeCode) { case XmlTypeCode.Integer: case XmlTypeCode.Decimal: case XmlTypeCode.Float: case XmlTypeCode.Double: return(new XPathAtomicValue(lvalue.ValueAsDouble + rvalue.ValueAsDouble, rvalue.XmlType)); } break; // datetimes case XmlTypeCode.Time: if (rvalue.XmlType.TypeCode == XmlTypeCode.DayTimeDuration) { goto case XmlTypeCode.DateTime; } break; case XmlTypeCode.DateTime: case XmlTypeCode.Date: switch (rvalue.XmlType.TypeCode) { case XmlTypeCode.YearMonthDuration: case XmlTypeCode.DayTimeDuration: return(new XPathAtomicValue(lvalue.ValueAsDateTime + new TimeSpan(rvalue.ValueAsDateTime.Ticks), lvalue.XmlType)); } break; // durations case XmlTypeCode.YearMonthDuration: switch (rvalue.XmlType.TypeCode) { case XmlTypeCode.Date: case XmlTypeCode.DateTime: return(new XPathAtomicValue(lvalue.ValueAsDateTime + new TimeSpan(rvalue.ValueAsDateTime.Ticks), rvalue.XmlType)); case XmlTypeCode.YearMonthDuration: return(new XPathAtomicValue(new DateTime(lvalue.ValueAsDateTime.Ticks + rvalue.ValueAsDateTime.Ticks), InternalPool.XdtYearMonthDuration)); } break; case XmlTypeCode.DayTimeDuration: switch (rvalue.XmlType.TypeCode) { case XmlTypeCode.Date: case XmlTypeCode.Time: case XmlTypeCode.DateTime: return(new XPathAtomicValue(lvalue.ValueAsDateTime + new TimeSpan(rvalue.ValueAsDateTime.Ticks), rvalue.XmlType)); case XmlTypeCode.DayTimeDuration: return(new XPathAtomicValue(new DateTime(lvalue.ValueAsDateTime.Ticks + rvalue.ValueAsDateTime.Ticks), InternalPool.XdtDayTimeDuration)); } break; } throw new XmlQueryException(String.Format("Not allowed arithmetic operation: {0} + {1}", lvalue.XmlType.QualifiedName, rvalue.XmlType.QualifiedName)); }
/// <summary> /// x + y /// </summary> public static XPathAtomicValue Add (XPathAtomicValue lvalue, XPathAtomicValue rvalue) { // numeric, date, time, dateTime, yearMonthDuration, dayTimeDuration switch (lvalue.XmlType.TypeCode) { // numerics case XmlTypeCode.Integer: switch (rvalue.XmlType.TypeCode) { case XmlTypeCode.Integer: return new XPathAtomicValue (lvalue.ValueAsInt64 + rvalue.ValueAsInt64, rvalue.XmlType); case XmlTypeCode.Decimal: return new XPathAtomicValue (lvalue.ValueAsDecimal + rvalue.ValueAsDecimal, rvalue.XmlType); case XmlTypeCode.Float: case XmlTypeCode.Double: return new XPathAtomicValue (lvalue.ValueAsDouble + rvalue.ValueAsDouble, rvalue.XmlType); } break; case XmlTypeCode.Decimal: switch (rvalue.XmlType.TypeCode) { case XmlTypeCode.Integer: case XmlTypeCode.Decimal: return new XPathAtomicValue (lvalue.ValueAsDecimal + rvalue.ValueAsDecimal, rvalue.XmlType); case XmlTypeCode.Float: case XmlTypeCode.Double: return new XPathAtomicValue (lvalue.ValueAsDouble + rvalue.ValueAsDouble, rvalue.XmlType); } break; case XmlTypeCode.Float: case XmlTypeCode.Double: switch (rvalue.XmlType.TypeCode) { case XmlTypeCode.Integer: case XmlTypeCode.Decimal: case XmlTypeCode.Float: case XmlTypeCode.Double: return new XPathAtomicValue (lvalue.ValueAsDouble + rvalue.ValueAsDouble, rvalue.XmlType); } break; // datetimes case XmlTypeCode.Time: if (rvalue.XmlType.TypeCode == XmlTypeCode.DayTimeDuration) goto case XmlTypeCode.DateTime; break; case XmlTypeCode.DateTime: case XmlTypeCode.Date: switch (rvalue.XmlType.TypeCode) { case XmlTypeCode.YearMonthDuration: case XmlTypeCode.DayTimeDuration: return new XPathAtomicValue (lvalue.ValueAsDateTime + new TimeSpan (rvalue.ValueAsDateTime.Ticks), lvalue.XmlType); } break; // durations case XmlTypeCode.YearMonthDuration: switch (rvalue.XmlType.TypeCode) { case XmlTypeCode.Date: case XmlTypeCode.DateTime: return new XPathAtomicValue (lvalue.ValueAsDateTime + new TimeSpan (rvalue.ValueAsDateTime.Ticks), rvalue.XmlType); case XmlTypeCode.YearMonthDuration: return new XPathAtomicValue (new DateTime (lvalue.ValueAsDateTime.Ticks + rvalue.ValueAsDateTime.Ticks), InternalPool.XdtYearMonthDuration); } break; case XmlTypeCode.DayTimeDuration: switch (rvalue.XmlType.TypeCode) { case XmlTypeCode.Date: case XmlTypeCode.Time: case XmlTypeCode.DateTime: return new XPathAtomicValue (lvalue.ValueAsDateTime + new TimeSpan (rvalue.ValueAsDateTime.Ticks), rvalue.XmlType); case XmlTypeCode.DayTimeDuration: return new XPathAtomicValue (new DateTime (lvalue.ValueAsDateTime.Ticks + rvalue.ValueAsDateTime.Ticks), InternalPool.XdtDayTimeDuration); } break; } throw new XmlQueryException (String.Format ("Not allowed arithmetic operation: {0} + {1}", lvalue.XmlType.QualifiedName, rvalue.XmlType.QualifiedName)); }
public static object FnTrace (XQueryContext ctx, object value, string label) { if (value == null) return new XPathEmptySequence (ctx); XPathSequence seq = value as XPathSequence; if (seq == null) { XPathAtomicValue av = value as XPathAtomicValue; if (av == null) av = new XPathAtomicValue (value, InternalPool.GetBuiltInType ( InternalPool.XmlTypeCodeFromRuntimeType ( value.GetType (), true))); seq = new SingleItemIterator (av, ctx); } return new TracingIterator (seq, label); }
private XPathAtomicValue Compute (XPathAtomicValue lvalue, XPathAtomicValue rvalue) { switch (Operation) { case ArithmeticOperator.Add: return XQueryArithmeticOperator.Add (lvalue, rvalue); case ArithmeticOperator.Sub: return XQueryArithmeticOperator.Subtract (lvalue, rvalue); case ArithmeticOperator.Mul: return XQueryArithmeticOperator.Multiply (lvalue, rvalue); case ArithmeticOperator.Div: return XQueryArithmeticOperator.Divide (lvalue, rvalue); case ArithmeticOperator.IDiv: return XQueryArithmeticOperator.IntDivide (lvalue, rvalue); case ArithmeticOperator.IMod: return XQueryArithmeticOperator.Remainder (lvalue, rvalue); default: throw new SystemException ("XQuery internal error: should not happen."); } }