コード例 #1
0
        /// <summary>
        /// Reads a single value.
        /// </summary>
        /// <param name="Reader">Binary reader.</param>
        /// <param name="FieldDataType">Field data type.</param>
        /// <returns>Single value.</returns>
        /// <exception cref="ArgumentException">If the <paramref name="FieldDataType"/> was invalid.</exception>
        public static float ReadSingle(BinaryDeserializer Reader, uint FieldDataType)
        {
            switch (FieldDataType)
            {
            case ObjectSerializer.TYPE_BOOLEAN: return(Reader.ReadBoolean() ? 1 : 0);

            case ObjectSerializer.TYPE_BYTE: return(Reader.ReadByte());

            case ObjectSerializer.TYPE_INT16: return(Reader.ReadInt16());

            case ObjectSerializer.TYPE_INT32: return(Reader.ReadInt32());

            case ObjectSerializer.TYPE_INT64: return(Reader.ReadInt64());

            case ObjectSerializer.TYPE_SBYTE: return(Reader.ReadSByte());

            case ObjectSerializer.TYPE_UINT16: return(Reader.ReadUInt16());

            case ObjectSerializer.TYPE_UINT32: return(Reader.ReadUInt32());

            case ObjectSerializer.TYPE_UINT64: return(Reader.ReadUInt64());

            case ObjectSerializer.TYPE_DECIMAL: return((float)Reader.ReadDecimal());

            case ObjectSerializer.TYPE_DOUBLE: return((float)Reader.ReadDouble());

            case ObjectSerializer.TYPE_SINGLE: return(Reader.ReadSingle());

            case ObjectSerializer.TYPE_STRING: return(float.Parse(Reader.ReadString()));

            default:
                throw new ArgumentException("Expected a single value, but was a " +
                                            FilesProvider.GetFieldDataTypeName(FieldDataType) + ".", nameof(FieldDataType));
            }
        }
コード例 #2
0
        /// <summary>
        /// Reads a GUID value.
        /// </summary>
        /// <param name="Reader">Binary reader.</param>
        /// <param name="FieldDataType">Field data type.</param>
        /// <returns>Guid value.</returns>
        /// <exception cref="ArgumentException">If the <paramref name="FieldDataType"/> was invalid.</exception>
        public static Guid ReadGuid(BinaryDeserializer Reader, uint FieldDataType)
        {
            switch (FieldDataType)
            {
            case ObjectSerializer.TYPE_GUID: return(Reader.ReadGuid());

            case ObjectSerializer.TYPE_STRING: return(Guid.Parse(Reader.ReadString()));

            default:
                throw new ArgumentException("Expected a GUID value, but was a " +
                                            FilesProvider.GetFieldDataTypeName(FieldDataType) + ".", nameof(FieldDataType));
            }
        }
コード例 #3
0
        /// <summary>
        /// Reads a time span value.
        /// </summary>
        /// <param name="Reader">Binary reader.</param>
        /// <param name="FieldDataType">Field data type.</param>
        /// <returns>TimeSpan value.</returns>
        /// <exception cref="ArgumentException">If the <paramref name="FieldDataType"/> was invalid.</exception>
        public static TimeSpan ReadTimeSpan(BinaryDeserializer Reader, uint FieldDataType)
        {
            switch (FieldDataType)
            {
            case ObjectSerializer.TYPE_TIMESPAN: return(Reader.ReadTimeSpan());

            case ObjectSerializer.TYPE_STRING: return(TimeSpan.Parse(Reader.ReadString()));

            default:
                throw new ArgumentException("Expected a time span value, but was a " +
                                            FilesProvider.GetFieldDataTypeName(FieldDataType) + ".", nameof(FieldDataType));
            }
        }
コード例 #4
0
        /// <summary>
        /// Reads a date &amp; time value.
        /// </summary>
        /// <param name="Reader">Binary reader.</param>
        /// <param name="FieldDataType">Field data type.</param>
        /// <returns>DateTime value.</returns>
        /// <exception cref="ArgumentException">If the <paramref name="FieldDataType"/> was invalid.</exception>
        public static DateTime ReadDateTime(BinaryDeserializer Reader, uint FieldDataType)
        {
            switch (FieldDataType)
            {
            case ObjectSerializer.TYPE_DATETIME: return(Reader.ReadDateTime());

            case ObjectSerializer.TYPE_STRING: return(DateTime.Parse(Reader.ReadString()));

            default:
                throw new ArgumentException("Expected a date & time value, but was a " +
                                            FilesProvider.GetFieldDataTypeName(FieldDataType) + ".", nameof(FieldDataType));
            }
        }
コード例 #5
0
        /// <summary>
        /// Reads a string value.
        /// </summary>
        /// <param name="Reader">Binary reader.</param>
        /// <param name="FieldDataType">Field data type.</param>
        /// <returns>String value.</returns>
        /// <exception cref="ArgumentException">If the <paramref name="FieldDataType"/> was invalid.</exception>
        public static string ReadString(BinaryDeserializer Reader, uint FieldDataType)
        {
            switch (FieldDataType)
            {
            case ObjectSerializer.TYPE_STRING: return(Reader.ReadString());

            case ObjectSerializer.TYPE_ENUM: return(Reader.ReadString());

            case ObjectSerializer.TYPE_NULL: return(null);

            case ObjectSerializer.TYPE_CHAR: return(new string(Reader.ReadChar(), 1));

            case ObjectSerializer.TYPE_BOOLEAN: return(Reader.ReadBoolean().ToString());

            case ObjectSerializer.TYPE_BYTE: return(Reader.ReadByte().ToString());

            case ObjectSerializer.TYPE_INT16: return(Reader.ReadInt16().ToString());

            case ObjectSerializer.TYPE_INT32: return(Reader.ReadInt32().ToString());

            case ObjectSerializer.TYPE_INT64: return(Reader.ReadInt64().ToString());

            case ObjectSerializer.TYPE_SBYTE: return(Reader.ReadSByte().ToString());

            case ObjectSerializer.TYPE_UINT16: return(Reader.ReadUInt16().ToString());

            case ObjectSerializer.TYPE_UINT32: return(Reader.ReadUInt32().ToString());

            case ObjectSerializer.TYPE_UINT64: return(Reader.ReadUInt64().ToString());

            case ObjectSerializer.TYPE_DECIMAL: return(Reader.ReadDecimal().ToString());

            case ObjectSerializer.TYPE_DOUBLE: return(Reader.ReadDouble().ToString());

            case ObjectSerializer.TYPE_SINGLE: return(Reader.ReadSingle().ToString());

            case ObjectSerializer.TYPE_DATETIME: return(Reader.ReadDateTime().ToString());

            case ObjectSerializer.TYPE_GUID: return(Reader.ReadSingle().ToString());

            case ObjectSerializer.TYPE_TIMESPAN: return(Reader.ReadSingle().ToString());

            default:
                throw new ArgumentException("Expected a char value, but was a " +
                                            FilesProvider.GetFieldDataTypeName(FieldDataType) + ".", nameof(FieldDataType));
            }
        }
コード例 #6
0
        /// <summary>
        /// Reads a char value.
        /// </summary>
        /// <param name="Reader">Binary reader.</param>
        /// <param name="FieldDataType">Field data type.</param>
        /// <returns>Char value.</returns>
        /// <exception cref="ArgumentException">If the <paramref name="FieldDataType"/> was invalid.</exception>
        public static char ReadChar(BinaryDeserializer Reader, uint FieldDataType)
        {
            switch (FieldDataType)
            {
            case ObjectSerializer.TYPE_CHAR: return(Reader.ReadChar());

            case ObjectSerializer.TYPE_BOOLEAN: return(Reader.ReadBoolean() ? (char)1 : (char)0);

            case ObjectSerializer.TYPE_BYTE: return((char)Reader.ReadByte());

            case ObjectSerializer.TYPE_INT16: return((char)Reader.ReadInt16());

            case ObjectSerializer.TYPE_INT32: return((char)Reader.ReadInt32());

            case ObjectSerializer.TYPE_INT64: return((char)Reader.ReadInt64());

            case ObjectSerializer.TYPE_SBYTE: return((char)Reader.ReadSByte());

            case ObjectSerializer.TYPE_UINT16: return((char)Reader.ReadUInt16());

            case ObjectSerializer.TYPE_UINT32: return((char)Reader.ReadUInt32());

            case ObjectSerializer.TYPE_UINT64: return((char)Reader.ReadUInt64());

            case ObjectSerializer.TYPE_DECIMAL: return((char)Reader.ReadDecimal());

            case ObjectSerializer.TYPE_DOUBLE: return((char)Reader.ReadDouble());

            case ObjectSerializer.TYPE_SINGLE: return((char)Reader.ReadSingle());

            case ObjectSerializer.TYPE_STRING:
                string s = Reader.ReadString();
                if (string.IsNullOrEmpty(s))
                {
                    return((char)0);
                }
                else
                {
                    return(s[0]);
                }

            default:
                throw new ArgumentException("Expected a char value, but was a " +
                                            FilesProvider.GetFieldDataTypeName(FieldDataType) + ".", nameof(FieldDataType));
            }
        }