Пример #1
0
        private object ReadMember(BinaryReader reader, BoisMemberInfo memInfo, Type memType)
        {
            if ((memInfo.IsNullable && memInfo.IsContainerObject) ||
                (memInfo.IsNullable && !memInfo.IsSupportedPrimitive && (!memInfo.IsContainerObject || memInfo.IsStruct)))
            {
                bool isNull = reader.ReadByte() != 0;

                if (isNull)
                {
                    return(null);
                }
            }
            var actualMemberType = memType;

            if (memInfo.IsNullable && memInfo.NullableUnderlyingType != null)
            {
                actualMemberType = memInfo.NullableUnderlyingType;
            }

            switch (memInfo.KnownType)
            {
            case EnBoisKnownType.Unknown:

                if (memInfo.IsContainerObject)
                {
                    return(ReadObject(reader, actualMemberType));
                }
                else if (memInfo.IsStringDictionary)
                {
                    return(ReadStringDictionary(reader, actualMemberType));
                }
                else if (memInfo.IsDictionary)
                {
                    return(ReadDictionary(reader, actualMemberType));
                }
                else if (memInfo.IsCollection)
                {
                    if (memInfo.IsGeneric)
                    {
                        return(ReadGenericList(reader, actualMemberType));
                    }
                    return(ReadArray(reader, actualMemberType));
                }
                else if (memInfo.IsArray)
                {
                    return(ReadArray(reader, actualMemberType));
                }

                break;

            case EnBoisKnownType.Int16:
                if (memInfo.IsNullable)
                {
                    return(PrimitivesConvertion.ReadVarInt16Nullable(reader));
                }
                return(PrimitivesConvertion.ReadVarInt16(reader));

            case EnBoisKnownType.UInt16:
                if (memInfo.IsNullable)
                {
                    return(PrimitivesConvertion.ReadVarUInt16Nullable(reader));
                }
                return(PrimitivesConvertion.ReadVarUInt16(reader));

            case EnBoisKnownType.Int32:
                if (memInfo.IsNullable)
                {
                    return(PrimitivesConvertion.ReadVarInt32Nullable(reader));
                }
                return(PrimitivesConvertion.ReadVarInt32(reader));

            case EnBoisKnownType.Int64:
                if (memInfo.IsNullable)
                {
                    return(PrimitivesConvertion.ReadVarInt64Nullable(reader));
                }
                return(PrimitivesConvertion.ReadVarInt64(reader));

            case EnBoisKnownType.UInt64:
                if (memInfo.IsNullable)
                {
                    return(PrimitivesConvertion.ReadVarUInt64Nullable(reader));
                }
                return(PrimitivesConvertion.ReadVarUInt64(reader));

            case EnBoisKnownType.UInt32:
                if (memInfo.IsNullable)
                {
                    return(PrimitivesConvertion.ReadVarUInt32Nullable(reader));
                }
                return(PrimitivesConvertion.ReadVarUInt32(reader));

            case EnBoisKnownType.Double:
                if (memInfo.IsNullable)
                {
                    return(PrimitivesConvertion.ReadVarDoubleNullable(reader));
                }
                return(PrimitivesConvertion.ReadVarDouble(reader));

            case EnBoisKnownType.Decimal:
                if (memInfo.IsNullable)
                {
                    return(PrimitivesConvertion.ReadVarDecimalNullable(reader));
                }
                return(PrimitivesConvertion.ReadVarDecimal(reader));

            case EnBoisKnownType.Single:
                if (memInfo.IsNullable)
                {
                    return(PrimitivesConvertion.ReadVarSingleNullable(reader));
                }
                return(PrimitivesConvertion.ReadVarSingle(reader));

            case EnBoisKnownType.Byte:
                return(reader.ReadByte());

            case EnBoisKnownType.SByte:
                return(reader.ReadSByte());

            case EnBoisKnownType.ByteArray:
                return(ReadBytes(reader));

            case EnBoisKnownType.String:
                return(ReadString(reader));

            case EnBoisKnownType.Char:
                var charByte = reader.ReadUInt16();
                return((char)charByte);

            case EnBoisKnownType.Bool:
                return(ReadBoolean(reader));

            case EnBoisKnownType.Enum:
                return(ReadEnum(reader, actualMemberType));

            case EnBoisKnownType.DateTime:
                return(ReadDateTime(reader));

            case EnBoisKnownType.DateTimeOffset:
                return(ReadDateTimeOffset(reader));

            case EnBoisKnownType.TimeSpan:
                return(ReadTimeSpan(reader));

#if !SILVERLIGHT && DotNet
            case EnBoisKnownType.DataSet:
                return(ReadDataset(reader, actualMemberType));

            case EnBoisKnownType.DataTable:
                return(ReadDataTable(reader));
#endif
#if DotNet || DotNetCore || DotNetStandard
            case EnBoisKnownType.NameValueColl:
                return(ReadCollectionNameValue(reader, actualMemberType));

            case EnBoisKnownType.Color:
                return(ReadColor(reader));

            case EnBoisKnownType.DbNull:
                return(DBNull.Value);
#endif

            case EnBoisKnownType.Version:
                return(ReadVersion(reader));

            case EnBoisKnownType.Guid:
                return(ReadGuid(reader));

            case EnBoisKnownType.Uri:
                return(ReadUri(reader));

            default:
                throw new ArgumentOutOfRangeException();
            }
            return(null);
        }