Beispiel #1
0
        private object DeserializePrimitive(XmlReader xmlReader, XmlDeserializationEvents events)
        {
            XmlSerializationPrimitiveReader reader = new XmlSerializationPrimitiveReader();
            reader.Init(xmlReader, events, null, null);
            object o;
            switch (_primitiveType.GetTypeCode())
            {
                case TypeCode.String:
                    o = reader.Read_string();
                    break;
                case TypeCode.Int32:
                    o = reader.Read_int();
                    break;
                case TypeCode.Boolean:
                    o = reader.Read_boolean();
                    break;
                case TypeCode.Int16:
                    o = reader.Read_short();
                    break;
                case TypeCode.Int64:
                    o = reader.Read_long();
                    break;
                case TypeCode.Single:
                    o = reader.Read_float();
                    break;
                case TypeCode.Double:
                    o = reader.Read_double();
                    break;
                case TypeCode.Decimal:
                    o = reader.Read_decimal();
                    break;
                case TypeCode.DateTime:
                    o = reader.Read_dateTime();
                    break;
                case TypeCode.Char:
                    o = reader.Read_char();
                    break;
                case TypeCode.Byte:
                    o = reader.Read_unsignedByte();
                    break;
                case TypeCode.SByte:
                    o = reader.Read_byte();
                    break;
                case TypeCode.UInt16:
                    o = reader.Read_unsignedShort();
                    break;
                case TypeCode.UInt32:
                    o = reader.Read_unsignedInt();
                    break;
                case TypeCode.UInt64:
                    o = reader.Read_unsignedLong();
                    break;

                default:
                    if (_primitiveType == typeof(XmlQualifiedName))
                    {
                        o = reader.Read_QName();
                    }
                    else if (_primitiveType == typeof(byte[]))
                    {
                        o = reader.Read_base64Binary();
                    }
                    else if (_primitiveType == typeof(Guid))
                    {
                        o = reader.Read_guid();
                    }
                    else if (_primitiveType == typeof(TimeSpan))
                    {
                        o = reader.Read_TimeSpan();
                    }
                    else
                    {
                        throw new InvalidOperationException(SR.Format(SR.XmlUnxpectedType, _primitiveType.FullName));
                    }
                    break;
            }
            return o;
        }
Beispiel #2
0
        object DeserializePrimitive(XmlReader xmlReader, XmlDeserializationEvents events)
        {
            XmlSerializationPrimitiveReader reader = new XmlSerializationPrimitiveReader();

            reader.Init(xmlReader, events, null, null);
            object o;

            switch (Type.GetTypeCode(primitiveType))
            {
            case TypeCode.String:
                o = reader.Read_string();
                break;

            case TypeCode.Int32:
                o = reader.Read_int();
                break;

            case TypeCode.Boolean:
                o = reader.Read_boolean();
                break;

            case TypeCode.Int16:
                o = reader.Read_short();
                break;

            case TypeCode.Int64:
                o = reader.Read_long();
                break;

            case TypeCode.Single:
                o = reader.Read_float();
                break;

            case TypeCode.Double:
                o = reader.Read_double();
                break;

            case TypeCode.Decimal:
                o = reader.Read_decimal();
                break;

            case TypeCode.DateTime:
                o = reader.Read_dateTime();
                break;

            case TypeCode.Char:
                o = reader.Read_char();
                break;

            case TypeCode.Byte:
                o = reader.Read_unsignedByte();
                break;

            case TypeCode.SByte:
                o = reader.Read_byte();
                break;

            case TypeCode.UInt16:
                o = reader.Read_unsignedShort();
                break;

            case TypeCode.UInt32:
                o = reader.Read_unsignedInt();
                break;

            case TypeCode.UInt64:
                o = reader.Read_unsignedLong();
                break;

            default:
                if (primitiveType == typeof(XmlQualifiedName))
                {
                    o = reader.Read_QName();
                }
                else if (primitiveType == typeof(byte[]))
                {
                    o = reader.Read_base64Binary();
                }
                else if (primitiveType == typeof(Guid))
                {
                    o = reader.Read_guid();
                }
                else if (primitiveType == typeof(TimeSpan) && LocalAppContextSwitches.EnableTimeSpanSerialization)
                {
                    o = reader.Read_TimeSpan();
                }
                else
                {
                    throw new InvalidOperationException(Res.GetString(Res.XmlUnxpectedType, primitiveType.FullName));
                }
                break;
            }
            return(o);
        }