using System.Text;
using System.Xml;
using System.Xml.Schema;
-using System.Xml.XPath;
namespace System.Xml
{
+ // basically this class is obsoleted and removed from .NET 2.0.
internal class XQueryConvert
{
private XQueryConvert ()
{
}
- public static bool ShouldCheckValueFacets (XmlSchemaType schemaTypeDest)
- {
- XmlSchemaObjectCollection facets = null;
- XmlSchemaSimpleType st = schemaTypeDest as XmlSchemaSimpleType;
- if (st != null) {
- XmlSchemaSimpleTypeRestriction r = st.Content
- as XmlSchemaSimpleTypeRestriction;
- if (r != null)
- facets = r.Facets;
- }
- else {
- XmlSchemaComplexType ct =
- schemaTypeDest as XmlSchemaComplexType;
- XmlSchemaSimpleContent sc = ct.ContentModel
- as XmlSchemaSimpleContent;
- if (sc != null) {
- XmlSchemaSimpleContentRestriction r =
- sc.Content as XmlSchemaSimpleContentRestriction;
- if (r != null)
- facets = r.Facets;
- }
- }
- return facets != null && facets.Count > 0;
- }
-
public static XmlTypeCode GetFallbackType (XmlTypeCode type)
{
switch (type) {
}
}
- [MonoTODO]
- // See XQuery & XPath 2.0 functions & operators section 17.
- public static bool CanConvert (XPathItem item, XmlSchemaType schemaTypeDest)
- {
- if (item == null)
- throw new ArgumentNullException ("item");
- if (schemaTypeDest == null)
- throw new ArgumentNullException ("schemaTypeDest");
- XmlTypeCode src = item.XmlType.TypeCode;
- XmlTypeCode dst = schemaTypeDest.TypeCode;
-
- // Notation cannot be converted from other than Notation
- if (src == XmlTypeCode.Notation && dst != XmlTypeCode.Notation)
- return false;
-
- // untypedAtomic and string are convertable unless source type is QName.
- switch (dst) {
- case XmlTypeCode.UntypedAtomic:
- case XmlTypeCode.String:
- return src != XmlTypeCode.QName;
- }
-
- switch (src) {
- case XmlTypeCode.None:
- case XmlTypeCode.Item:
- case XmlTypeCode.Node:
- case XmlTypeCode.Document:
- case XmlTypeCode.Element:
- case XmlTypeCode.Attribute:
- case XmlTypeCode.Namespace:
- case XmlTypeCode.ProcessingInstruction:
- case XmlTypeCode.Comment:
- case XmlTypeCode.Text:
- throw new NotImplementedException (); // FIXME: check what happens
-
- case XmlTypeCode.AnyAtomicType:
- throw new NotImplementedException (); // FIXME: check what happens
- case XmlTypeCode.UntypedAtomic:
- case XmlTypeCode.String:
- // 'M'
- throw new NotImplementedException (); // FIXME: check what happens
-
- case XmlTypeCode.Boolean:
- case XmlTypeCode.Decimal:
- switch (dst) {
- case XmlTypeCode.Float:
- case XmlTypeCode.Double:
- case XmlTypeCode.Decimal:
- case XmlTypeCode.Boolean:
- return true;
- }
- return false;
-
- case XmlTypeCode.Float:
- case XmlTypeCode.Double:
- if (dst == XmlTypeCode.Decimal)
- // 'M'
- throw new NotImplementedException (); // FIXME: check what happens
- goto case XmlTypeCode.Decimal;
-
- case XmlTypeCode.Duration:
- switch (dst) {
- case XmlTypeCode.Duration:
- case XmlTypeCode.YearMonthDuration:
- case XmlTypeCode.DayTimeDuration:
- return true;
- }
- return false;
-
- case XmlTypeCode.DateTime:
- switch (dst) {
- case XmlTypeCode.DateTime:
- case XmlTypeCode.Time:
- case XmlTypeCode.Date:
- case XmlTypeCode.GYearMonth:
- case XmlTypeCode.GYear:
- case XmlTypeCode.GMonthDay:
- case XmlTypeCode.GDay:
- case XmlTypeCode.GMonth:
- return true;
- }
- return false;
-
- case XmlTypeCode.Time:
- switch (dst) {
- case XmlTypeCode.Time:
- case XmlTypeCode.Date:
- return true;
- }
- return false;
-
- case XmlTypeCode.Date:
- if (dst == XmlTypeCode.Time)
- return false;
- goto case XmlTypeCode.DateTime;
-
- case XmlTypeCode.GYearMonth:
- case XmlTypeCode.GYear:
- case XmlTypeCode.GMonthDay:
- case XmlTypeCode.GDay:
- case XmlTypeCode.GMonth:
- return src == dst;
-
- case XmlTypeCode.HexBinary:
- case XmlTypeCode.Base64Binary:
- if (src == dst)
- return true;
- switch (dst) {
- case XmlTypeCode.HexBinary:
- case XmlTypeCode.Base64Binary:
- return true;
- }
- return false;
-
- case XmlTypeCode.AnyUri:
- case XmlTypeCode.QName:
- case XmlTypeCode.Notation:
- return src == dst;
-
- case XmlTypeCode.NormalizedString:
- case XmlTypeCode.Token:
- case XmlTypeCode.Language:
- case XmlTypeCode.NmToken:
- case XmlTypeCode.Name:
- case XmlTypeCode.NCName:
- case XmlTypeCode.Id:
- case XmlTypeCode.Idref:
- case XmlTypeCode.Entity:
- case XmlTypeCode.Integer:
- case XmlTypeCode.NonPositiveInteger:
- case XmlTypeCode.NegativeInteger:
- case XmlTypeCode.Long:
- case XmlTypeCode.Int:
- case XmlTypeCode.Short:
- case XmlTypeCode.Byte:
- case XmlTypeCode.NonNegativeInteger:
- case XmlTypeCode.UnsignedLong:
- case XmlTypeCode.UnsignedInt:
- case XmlTypeCode.UnsignedShort:
- case XmlTypeCode.UnsignedByte:
- case XmlTypeCode.PositiveInteger:
- throw new NotImplementedException ();
-
- // xdt:*
- case XmlTypeCode.YearMonthDuration:
- if (dst == XmlTypeCode.DayTimeDuration)
- return false;
- goto case XmlTypeCode.Duration;
- case XmlTypeCode.DayTimeDuration:
- if (dst == XmlTypeCode.YearMonthDuration)
- return false;
- goto case XmlTypeCode.Duration;
- }
-
- throw new NotImplementedException ();
- }
-
// Individual conversion
public static string AnyUriToString (string value)
return Convert.ToInt64 (value);
}
- [MonoTODO] // what if value was negative?
- public static decimal DecimalToNonNegativeInteger (decimal value)
- {
- // MS has a bug that does not reject negative values.
- throw new NotImplementedException ();
- }
-
- [MonoTODO] // what if value was positive?
- public static decimal DecimalToNonPositiveInteger (decimal value)
- {
- throw new NotImplementedException ();
- }
-
public static string DecimalToString (decimal value)
{
return XmlConvert.ToString (value);
return Convert.ToInt64 (value);
}
- [MonoTODO] // what if value was negative?
- public static decimal DoubleToNonNegativeInteger (double value)
- {
- // MS has a bug that does not reject negative values.
- throw new NotImplementedException ();
- }
-
- [MonoTODO] // what if value was positive?
- public static decimal DoubleToNonPositiveInteger (double value)
- {
- throw new NotImplementedException ();
- }
-
public static string DoubleToString (double value)
{
return XmlConvert.ToString (value);
return Convert.ToInt64 (value);
}
- [MonoTODO] // what if value was negative?
- public static decimal FloatToNonNegativeInteger (float value)
- {
- // MS has a bug that does not reject negative values.
- throw new NotImplementedException ();
- }
-
- [MonoTODO] // what if value was positive?
- public static decimal FloatToNonPositiveInteger (float value)
- {
- throw new NotImplementedException ();
- }
-
public static string FloatToString (float value)
{
return XmlConvert.ToString (value);
public static string GMonthToString (DateTime value)
{
- return XmlConvert.ToString (new TimeSpan (0, value.Month, 0));
+ return XmlConvert.ToString (new TimeSpan (0, value.Month, 1));
}
public static string GYearMonthToString (DateTime value)
{
- return XmlConvert.ToString (new TimeSpan (value.Year, value.Month, 0));
+ return XmlConvert.ToString (new TimeSpan (value.Year, value.Month, 1));
}
public static string GYearToString (DateTime value)
{
- return XmlConvert.ToString (new TimeSpan (new DateTime (value.Year, 0, 0).Ticks));
+ return XmlConvert.ToString (new TimeSpan (new DateTime (value.Year, 1, 1).Ticks));
}
public static string HexBinaryToString (byte [] data)
return (decimal) value;
}
+ public static decimal IntegerToDecimal (ulong value)
+ {
+ return (decimal) value;
+ }
+
public static double IntegerToDouble (long value)
{
return Convert.ToDouble (value);
return XmlConvert.ToDateTime (value);
}
- public static long StringToUnsignedInt (string value)
+ public static UInt32 StringToUnsignedInt (string value)
{
return XmlConvert.ToUInt32 (value);
}
- public static decimal StringToUnsignedLong (string value)
+ public static UInt64 StringToUnsignedLong (string value)
{
return XmlConvert.ToUInt64 (value);
}
- public static int StringToUnsignedShort (string value)
+ public static UInt16 StringToUnsignedShort (string value)
{
return XmlConvert.ToUInt16 (value);
}
{
return XmlConvert.ToTimeSpan (value);
}
-
- public static string ItemToAnyUri (XPathItem value)
- {
- return value.Value;
- }
-
- public static byte [] ItemToBase64Binary (XPathItem value)
- {
- return Convert.FromBase64String (value.Value);
- }
-
- public static bool ItemToBoolean (XPathItem value)
- {
- return XmlConvert.ToBoolean (value.Value);
- }
-
- public static DateTime ItemToDate (XPathItem value)
- {
- return XmlConvert.ToDateTime (value.Value);
- }
-
- public static DateTime ItemToDateTime (XPathItem value)
- {
- return XmlConvert.ToDateTime (value.Value);
- }
-
- public static TimeSpan ItemToDayTimeDuration (XPathItem value)
- {
- return XmlConvert.ToTimeSpan (value.Value);
- }
-
- public static decimal ItemToDecimal (XPathItem value)
- {
- return XmlConvert.ToDecimal (value.Value);
- }
-
- public static double ItemToDouble (XPathItem value)
- {
- return XmlConvert.ToDouble (value.Value);
- }
-
- public static string ItemToDuration (XPathItem value)
- {
- return XmlConvert.ToString (XmlConvert.ToTimeSpan (value.Value));
- }
-
- public static float ItemToFloat (XPathItem value)
- {
- return XmlConvert.ToSingle (value.Value);
- }
-
- public static DateTime ItemToGDay (XPathItem value)
- {
- return XmlConvert.ToDateTime (value.Value);
- }
-
- public static DateTime ItemToGMonth (XPathItem value)
- {
- return XmlConvert.ToDateTime (value.Value);
- }
-
- public static DateTime ItemToGMonthDay (XPathItem value)
- {
- return XmlConvert.ToDateTime (value.Value);
- }
-
- public static DateTime ItemToGYear (XPathItem value)
- {
- return XmlConvert.ToDateTime (value.Value);
- }
-
- public static DateTime ItemToGYearMonth (XPathItem value)
- {
- return XmlConvert.ToDateTime (value.Value);
- }
-
- public static byte [] ItemToHexBinary (XPathItem value)
- {
- return XmlConvert.FromBinHexString (value.Value);
- }
-
- public static int ItemToInt (XPathItem value)
- {
- return XmlConvert.ToInt32 (value.Value);
- }
-
- public static long ItemToInteger (XPathItem value)
- {
- return XmlConvert.ToInt64 (value.Value);
- }
-
- public static XPathItem ItemToItem (XPathItem value, XmlSchemaType schemaTypeDest)
- {
- return new XmlAtomicValue (value.Value, schemaTypeDest);
- }
-
- public static decimal ItemToNonNegativeInteger (XPathItem value)
- {
- return XmlConvert.ToDecimal (value.Value);
- }
-
- public static decimal ItemToNonPositiveInteger (XPathItem value)
- {
- return XmlConvert.ToDecimal (value.Value);
- }
-
- public static XmlQualifiedName ItemToQName (XPathItem value)
- {
- return (XmlQualifiedName) value.TypedValue;
- }
-
- public static string ItemToString (XPathItem value)
- {
- if (value.ValueType == typeof (DateTime))
- return XmlConvert.ToString ((DateTime) value.TypedValue);
- if (value.TypedValue is XmlQualifiedName)
- throw new ArgumentException ("Invalid cast from schema QName type to string type.");
- return value.Value;
- }
-
- public static DateTime ItemToTime (XPathItem value)
- {
- return XmlConvert.ToDateTime (value.Value);
- }
-
- [MonoTODO]
- public static long ItemToUnsignedInt (XPathItem value)
- {
- // FIXME: signed
- return XmlConvert.ToInt32 (value.Value);
- }
-
- [MonoTODO]
- public static decimal ItemToUnsignedLong (XPathItem value)
- {
- // FIXME: signed
- return XmlConvert.ToInt32 (value.Value);
- }
-
- [MonoTODO]
- public static int ItemToUnsignedShort (XPathItem value)
- {
- // FIXME: signed
- return XmlConvert.ToInt32 (value.Value);
- }
-
- public static TimeSpan ItemToYearMonthDuration (XPathItem value)
- {
- return XmlConvert.ToTimeSpan (value.Value);
- }
}
}