public override object ChangeType()

in src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/schema/XmlValueConverter.cs [2134:2246]


        public override object ChangeType(object value, Type destinationType, IXmlNamespaceResolver nsResolver)
        {
            if (value == null) throw new ArgumentNullException("value");
            if (destinationType == null) throw new ArgumentNullException("destinationType");

            Type sourceType = value.GetType();

            if (destinationType == ObjectType) destinationType = DefaultClrType;
            if (destinationType == ByteArrayType)
            {
                if (sourceType == ByteArrayType)
                {
                    switch (TypeCode)
                    {
                        case XmlTypeCode.Base64Binary: return ((byte[])value);
                        case XmlTypeCode.HexBinary: return ((byte[])value);
                    }
                }
                if (sourceType == StringType)
                {
                    switch (TypeCode)
                    {
                        case XmlTypeCode.Base64Binary: return StringToBase64Binary((string)value);
                        case XmlTypeCode.HexBinary: return StringToHexBinary((string)value);
                    }
                }
            }
            if (destinationType == XmlQualifiedNameType)
            {
                if (sourceType == StringType)
                {
                    switch (TypeCode)
                    {
                        case XmlTypeCode.Notation: return StringToQName((string)value, nsResolver);
                        case XmlTypeCode.QName: return StringToQName((string)value, nsResolver);
                    }
                }
                if (IsDerivedFrom(sourceType, XmlQualifiedNameType))
                {
                    switch (TypeCode)
                    {
                        case XmlTypeCode.Notation: return ((XmlQualifiedName)value);
                        case XmlTypeCode.QName: return ((XmlQualifiedName)value);
                    }
                }
            }
            if (destinationType == StringType) return this.ToString(value, nsResolver);
            if (destinationType == TimeSpanType)
            {
                if (sourceType == StringType)
                {
                    switch (TypeCode)
                    {
                        case XmlTypeCode.DayTimeDuration: return StringToDayTimeDuration((string)value);
                        case XmlTypeCode.Duration: return StringToDuration((string)value);
                        case XmlTypeCode.YearMonthDuration: return StringToYearMonthDuration((string)value);
                    }
                }
                if (sourceType == TimeSpanType)
                {
                    switch (TypeCode)
                    {
                        case XmlTypeCode.DayTimeDuration: return ((TimeSpan)value);
                        case XmlTypeCode.Duration: return ((TimeSpan)value);
                        case XmlTypeCode.YearMonthDuration: return ((TimeSpan)value);
                    }
                }
            }
            if (destinationType == UriType)
            {
                if (sourceType == StringType) if (TypeCode == XmlTypeCode.AnyUri) return XmlConvert.ToUri((string)value);
                if (IsDerivedFrom(sourceType, UriType)) if (TypeCode == XmlTypeCode.AnyUri) return ((Uri)value);
            }
            if (destinationType == XmlAtomicValueType)
            {
                if (sourceType == ByteArrayType)
                {
                    switch (TypeCode)
                    {
                        case XmlTypeCode.Base64Binary: return (new XmlAtomicValue(SchemaType, value));
                        case XmlTypeCode.HexBinary: return (new XmlAtomicValue(SchemaType, value));
                    }
                }
                if (sourceType == StringType) return (new XmlAtomicValue(SchemaType, (string)value, nsResolver));
                if (sourceType == TimeSpanType)
                {
                    switch (TypeCode)
                    {
                        case XmlTypeCode.DayTimeDuration: return (new XmlAtomicValue(SchemaType, value));
                        case XmlTypeCode.Duration: return (new XmlAtomicValue(SchemaType, value));
                        case XmlTypeCode.YearMonthDuration: return (new XmlAtomicValue(SchemaType, value));
                    }
                }
                if (IsDerivedFrom(sourceType, UriType)) if (TypeCode == XmlTypeCode.AnyUri) return (new XmlAtomicValue(SchemaType, value));
                if (sourceType == XmlAtomicValueType) return ((XmlAtomicValue)value);
                if (IsDerivedFrom(sourceType, XmlQualifiedNameType))
                {
                    switch (TypeCode)
                    {
                        case XmlTypeCode.Notation: return (new XmlAtomicValue(SchemaType, value, nsResolver));
                        case XmlTypeCode.QName: return (new XmlAtomicValue(SchemaType, value, nsResolver));
                    }
                }
            }
            if (destinationType == XPathItemType)
            {
                if (sourceType == XmlAtomicValueType) return ((XmlAtomicValue)value);
            }
            if (destinationType == XPathItemType) return ((XPathItem)this.ChangeType(value, XmlAtomicValueType, nsResolver));
            if (sourceType == XmlAtomicValueType) return ((XmlAtomicValue)value).ValueAs(destinationType, nsResolver);

            return ChangeListType(value, destinationType, nsResolver);
        }