Пример #1
0
        public void WriteValue(PrimitiveTypeEnum code, object value)
        {
            switch (code)
            {
            case PrimitiveTypeEnum.Boolean:
                this.Write(Utilities.Cast <bool>(value));
                return;

            case PrimitiveTypeEnum.Byte:
                this.Write(Utilities.Cast <byte>(value));
                return;

            case PrimitiveTypeEnum.Char:
                this.Write(Utilities.Cast <char>(value));
                return;

            case PrimitiveTypeEnum.Decimal:
                this.Write(Utilities.Cast <decimal>(value));
                return;

            case PrimitiveTypeEnum.Double:
                this.Write(Utilities.Cast <double>(value));
                return;

            case PrimitiveTypeEnum.Int16:
                this.Write(Utilities.Cast <short>(value));
                return;

            case PrimitiveTypeEnum.Int32:
                this.Write(Utilities.Cast <int>(value));
                return;

            case PrimitiveTypeEnum.Int64:
                this.Write(Utilities.Cast <long>(value));
                return;

            case PrimitiveTypeEnum.SByte:
                this.Write(Utilities.Cast <sbyte>(value));
                return;

            case PrimitiveTypeEnum.Single:
                this.Write(Utilities.Cast <float>(value));
                return;

            case PrimitiveTypeEnum.TimeSpan:
                this.Write(Utilities.Cast <TimeSpan>(value).Ticks);
                return;

            case PrimitiveTypeEnum.DateTime:
                this.Write(Utilities.Cast <DateTime>(value));
                return;

            case PrimitiveTypeEnum.UInt16:
                this.Write(Utilities.Cast <ushort>(value));
                return;

            case PrimitiveTypeEnum.UInt32:
                this.Write(Utilities.Cast <uint>(value));
                return;

            case PrimitiveTypeEnum.UInt64:
                this.Write(Utilities.Cast <ulong>(value));
                return;
            }
            throw new SerializationException(RemotingResources.SerializationTypeCode.Format(code.ToString()));
        }
Пример #2
0
        internal object ReadValue(PrimitiveTypeEnum code)
        {
            object obj2;

#pragma warning disable IDE0066 // Convert switch statement to expression
            switch (code)
#pragma warning restore IDE0066 // Convert switch statement to expression
            {
            case PrimitiveTypeEnum.Boolean:
                obj2 = ReadBoolean();
                break;

            case PrimitiveTypeEnum.Byte:
                obj2 = ReadByte();
                break;

            case PrimitiveTypeEnum.Char:
                obj2 = ReadChar();
                break;

            case PrimitiveTypeEnum.Decimal:
                obj2 = ReadDecimal();
                break;

            case PrimitiveTypeEnum.Double:
                obj2 = (double)ReadDouble();
                break;

            case PrimitiveTypeEnum.Int16:
                obj2 = ReadInt16();
                break;

            case PrimitiveTypeEnum.Int32:
                obj2 = ReadInt32();
                break;

            case PrimitiveTypeEnum.Int64:
                obj2 = ReadInt64();
                break;

            case PrimitiveTypeEnum.SByte:
                obj2 = ReadSByte();
                break;

            case PrimitiveTypeEnum.Single:
                obj2 = (float)ReadSingle();
                break;

            case PrimitiveTypeEnum.TimeSpan:
                obj2 = ReadTimeSpan();
                break;

            case PrimitiveTypeEnum.DateTime:
                obj2 = ReadDateTime();
                break;

            case PrimitiveTypeEnum.UInt16:
                obj2 = ReadUInt16();
                break;

            case PrimitiveTypeEnum.UInt32:
                obj2 = ReadUInt32();
                break;

            case PrimitiveTypeEnum.UInt64:
                obj2 = ReadUInt64();
                break;

            default:
                throw new SerializationException(RemotingResources.SerializationTypeCode.Format(code.ToString()));
            }
            return(obj2);
        }