// TODO: write a generic method for each Primitive type, in order to avoid boxing to object. internal Object ReadPrimitiveObjectFromBinaryStream(FileTools.BinaryReader2 binaryReader, L3TypeManager typeManager, bool CompressIntsAs7Bits) { TypeCode tc = (TypeCode)typeManager.TypeIndex; #if DEBUG if ((int)tc < (int)TypeCode.Boolean) throw new ArgumentException("data is not a Primitive type"); #endif switch (tc) { case TypeCode.Boolean: return binaryReader.ReadBoolean(); case TypeCode.Byte: return binaryReader.ReadByte(); case TypeCode.Char: return binaryReader.ReadChar(); case TypeCode.DateTime: return new DateTime(binaryReader.ReadInt64()); case TypeCode.Decimal: return binaryReader.ReadDecimal(); case TypeCode.Double: return binaryReader.ReadDouble(); case TypeCode.SByte: return binaryReader.ReadSByte(); case TypeCode.Single: return binaryReader.ReadSingle(); case TypeCode.String: return binaryReader.ReadString(); case TypeCode.Int16: if (CompressIntsAs7Bits) return binaryReader.ReadSpecial7BitEncodedShort(); else return binaryReader.ReadInt16(); case TypeCode.Int32: if (CompressIntsAs7Bits) return binaryReader.ReadSpecial7BitEncodedInt(); else return binaryReader.ReadInt32(); case TypeCode.Int64: if (CompressIntsAs7Bits) return binaryReader.ReadSpecial7BitEncodedLong(); else return binaryReader.ReadInt64(); case TypeCode.UInt16: if (CompressIntsAs7Bits) return binaryReader.Read7BitEncodedUShort(); else return binaryReader.ReadUInt16(); case TypeCode.UInt32: if (CompressIntsAs7Bits) return binaryReader.Read7BitEncodedUInt(); else return binaryReader.ReadUInt32(); case TypeCode.UInt64: if (CompressIntsAs7Bits) return binaryReader.Read7BitEncodedULong(); else return binaryReader.ReadUInt64(); default: #if DEBUG throw new Exception(); #else return null; #endif } }