public static string GetXsdValue(object value) { if (value is DateTime) { return(SoapDateTime.ToString((DateTime)value)); } else if (value is decimal) { return(((decimal)value).ToString(CultureInfo.InvariantCulture)); } else if (value is double) { return(((double)value).ToString("G17", CultureInfo.InvariantCulture)); } else if (value is float) { return(((float)value).ToString("G9", CultureInfo.InvariantCulture)); } else if (value is TimeSpan) { return(SoapDuration.ToString((TimeSpan)value)); } else if (value is bool) { return(((bool)value) ? "true" : "false"); } else if (value is MethodSignature) { return(null); } else { return(value.ToString()); } }
public static void Main(string[] args) { // Parse an XSD dateTime to create a DateTime object. string xsdDateTime = "2003-02-04T13:58:59.9999999+03:00"; DateTime dateTime = SoapDateTime.Parse(xsdDateTime); // Serialize a DateTime object as an XSD dateTime string. Console.WriteLine("The date in XSD format is {0}.", SoapDateTime.ToString(dateTime)); // Print the XSD type string of the SoapDateTime class. Console.WriteLine("The XSD type of SoapDateTime is {0}.", SoapDateTime.XsdType); }
internal static string ToString(object data, InternalPrimitiveTypeE code) { switch (code) { case InternalPrimitiveTypeE.Invalid: return(data.ToString()); case InternalPrimitiveTypeE.Boolean: if (!((bool)data)) { return("false"); } return("true"); case InternalPrimitiveTypeE.Double: { double d = (double)data; if (!double.IsPositiveInfinity(d)) { if (double.IsNegativeInfinity(d)) { return("-INF"); } return(d.ToString("R", CultureInfo.InvariantCulture)); } return("INF"); } case InternalPrimitiveTypeE.Single: { float f = (float)data; if (!float.IsPositiveInfinity(f)) { if (float.IsNegativeInfinity(f)) { return("-INF"); } return(f.ToString("R", CultureInfo.InvariantCulture)); } return("INF"); } case InternalPrimitiveTypeE.TimeSpan: return(SoapDuration.ToString((TimeSpan)data)); case InternalPrimitiveTypeE.DateTime: return(SoapDateTime.ToString((DateTime)data)); case InternalPrimitiveTypeE.Time: case InternalPrimitiveTypeE.Date: case InternalPrimitiveTypeE.YearMonth: case InternalPrimitiveTypeE.Year: case InternalPrimitiveTypeE.MonthDay: case InternalPrimitiveTypeE.Day: case InternalPrimitiveTypeE.Month: case InternalPrimitiveTypeE.HexBinary: case InternalPrimitiveTypeE.Base64Binary: case InternalPrimitiveTypeE.Integer: case InternalPrimitiveTypeE.PositiveInteger: case InternalPrimitiveTypeE.NonPositiveInteger: case InternalPrimitiveTypeE.NonNegativeInteger: case InternalPrimitiveTypeE.NegativeInteger: case InternalPrimitiveTypeE.AnyUri: case InternalPrimitiveTypeE.QName: case InternalPrimitiveTypeE.Notation: case InternalPrimitiveTypeE.NormalizedString: case InternalPrimitiveTypeE.Token: case InternalPrimitiveTypeE.Language: case InternalPrimitiveTypeE.Name: case InternalPrimitiveTypeE.Idrefs: case InternalPrimitiveTypeE.Entities: case InternalPrimitiveTypeE.Nmtoken: case InternalPrimitiveTypeE.Nmtokens: case InternalPrimitiveTypeE.NcName: case InternalPrimitiveTypeE.Id: case InternalPrimitiveTypeE.Idref: case InternalPrimitiveTypeE.Entity: return(data.ToString()); } return((string)Convert.ChangeType(data, typeofString, CultureInfo.InvariantCulture)); }