public override string ToString(object value, IXmlNamespaceResolver nsResolver) { if (value == null) { throw new ArgumentNullException("value"); } Type derivedType = value.GetType(); if (derivedType == XmlBaseConverter.ByteArrayType) { switch (base.TypeCode) { case XmlTypeCode.HexBinary: return(XmlConvert.ToBinHexString((byte[])value)); case XmlTypeCode.Base64Binary: return(XmlBaseConverter.Base64BinaryToString((byte[])value)); } } if (derivedType == XmlBaseConverter.StringType) { return((string)value); } if (XmlBaseConverter.IsDerivedFrom(derivedType, XmlBaseConverter.UriType) && (base.TypeCode == XmlTypeCode.AnyUri)) { return(XmlBaseConverter.AnyUriToString((Uri)value)); } if (derivedType == XmlBaseConverter.TimeSpanType) { switch (base.TypeCode) { case XmlTypeCode.YearMonthDuration: return(XmlBaseConverter.YearMonthDurationToString((TimeSpan)value)); case XmlTypeCode.DayTimeDuration: return(XmlBaseConverter.DayTimeDurationToString((TimeSpan)value)); case XmlTypeCode.Duration: return(XmlBaseConverter.DurationToString((TimeSpan)value)); } } if (XmlBaseConverter.IsDerivedFrom(derivedType, XmlBaseConverter.XmlQualifiedNameType)) { switch (base.TypeCode) { case XmlTypeCode.QName: return(XmlBaseConverter.QNameToString((XmlQualifiedName)value, nsResolver)); case XmlTypeCode.Notation: return(XmlBaseConverter.QNameToString((XmlQualifiedName)value, nsResolver)); } } return((string)this.ChangeTypeWildcardDestination(value, XmlBaseConverter.StringType, nsResolver)); }
public override string ToString(object value, IXmlNamespaceResolver nsResolver) { if (value == null) { throw new ArgumentNullException("value"); } Type derivedType = value.GetType(); if (derivedType == XmlBaseConverter.BooleanType) { return(XmlConvert.ToString((bool)value)); } if (derivedType == XmlBaseConverter.ByteType) { return(XmlConvert.ToString((byte)value)); } if (derivedType == XmlBaseConverter.ByteArrayType) { return(XmlBaseConverter.Base64BinaryToString((byte[])value)); } if (derivedType == XmlBaseConverter.DateTimeType) { return(XmlBaseConverter.DateTimeToString((DateTime)value)); } if (derivedType == XmlBaseConverter.DateTimeOffsetType) { return(XmlBaseConverter.DateTimeOffsetToString((DateTimeOffset)value)); } if (derivedType == XmlBaseConverter.DecimalType) { return(XmlConvert.ToString((decimal)value)); } if (derivedType == XmlBaseConverter.DoubleType) { return(XmlConvert.ToString((double)value)); } if (derivedType == XmlBaseConverter.Int16Type) { return(XmlConvert.ToString((short)value)); } if (derivedType == XmlBaseConverter.Int32Type) { return(XmlConvert.ToString((int)value)); } if (derivedType == XmlBaseConverter.Int64Type) { return(XmlConvert.ToString((long)value)); } if (derivedType == XmlBaseConverter.SByteType) { return(XmlConvert.ToString((sbyte)value)); } if (derivedType == XmlBaseConverter.SingleType) { return(XmlConvert.ToString((float)value)); } if (derivedType == XmlBaseConverter.StringType) { return((string)value); } if (derivedType == XmlBaseConverter.TimeSpanType) { return(XmlBaseConverter.DurationToString((TimeSpan)value)); } if (derivedType == XmlBaseConverter.UInt16Type) { return(XmlConvert.ToString((ushort)value)); } if (derivedType == XmlBaseConverter.UInt32Type) { return(XmlConvert.ToString((uint)value)); } if (derivedType == XmlBaseConverter.UInt64Type) { return(XmlConvert.ToString((ulong)value)); } if (XmlBaseConverter.IsDerivedFrom(derivedType, XmlBaseConverter.UriType)) { return(XmlBaseConverter.AnyUriToString((Uri)value)); } if (derivedType == XmlBaseConverter.XmlAtomicValueType) { return((string)((XmlAtomicValue)value).ValueAs(XmlBaseConverter.StringType, nsResolver)); } if (XmlBaseConverter.IsDerivedFrom(derivedType, XmlBaseConverter.XmlQualifiedNameType)) { return(XmlBaseConverter.QNameToString((XmlQualifiedName)value, nsResolver)); } return((string)this.ChangeTypeWildcardDestination(value, XmlBaseConverter.StringType, nsResolver)); }