コード例 #1
0
        public static char ReadChar(NetworkBinaryReader reader)
        {
            object value = ReadNonnullObject("char", reader);

            if (value is char)
            {
                return((char)value);
            }
            PrimitiveParser.InvalidConversion("char", value);
            return((char)0);
        }
コード例 #2
0
        public static bool ReadBool(NetworkBinaryReader reader)
        {
            object value = ReadNonnullObject("bool", reader);

            if (value is bool)
            {
                return((bool)value);
            }
            if (value is string)
            {
                return(PrimitiveParser.ParseBool((string)value));
            }
            PrimitiveParser.InvalidConversion("bool", value);
            return(false);
        }
コード例 #3
0
        public static string ReadString(NetworkBinaryReader reader)
        {
            object value = ReadObject(reader);

            if (value == null)
            {
                return(null);
            }
            if (value is byte[])
            {
                PrimitiveParser.InvalidConversion("string", value);
                return(null);
            }
            return(value.ToString());
        }
コード例 #4
0
        public static byte[] ReadBytes(NetworkBinaryReader reader)
        {
            object value = ReadObject(reader);

            if (value == null)
            {
                return(null);
            }
            if (value is byte[])
            {
                return((byte[])value);
            }
            PrimitiveParser.InvalidConversion("byte[]", value);
            return(null);
        }
コード例 #5
0
        public static double ReadDouble(NetworkBinaryReader reader)
        {
            object value = ReadNonnullObject("double", reader);

            if (value is double || value is float)
            {
                return((double)value);
            }
            if (value is string)
            {
                return(PrimitiveParser.ParseDouble((string)value));
            }
            PrimitiveParser.InvalidConversion("double", value);
            return(0);
        }
コード例 #6
0
        public static float ReadSingle(NetworkBinaryReader reader)
        {
            object value = ReadNonnullObject("float", reader);

            if (value is float)
            {
                return((float)value);
            }
            if (value is string)
            {
                return(PrimitiveParser.ParseFloat((string)value));
            }
            PrimitiveParser.InvalidConversion("float", value);
            return(0);
        }
コード例 #7
0
        public static long ReadInt64(NetworkBinaryReader reader)
        {
            object value = ReadNonnullObject("long", reader);

            if (value is long || value is int || value is short || value is byte)
            {
                return((long)value);
            }
            if (value is string)
            {
                return(PrimitiveParser.ParseLong((string)value));
            }
            PrimitiveParser.InvalidConversion("long", value);
            return(0);
        }
コード例 #8
0
        public static byte ReadByte(NetworkBinaryReader reader)
        {
            object value = ReadNonnullObject("byte", reader);

            if (value is byte)
            {
                return((byte)value);
            }
            if (value is string)
            {
                return(PrimitiveParser.ParseByte((string)value));
            }
            PrimitiveParser.InvalidConversion("byte", value);
            return(0);
        }
コード例 #9
0
        public static short ReadInt16(NetworkBinaryReader reader)
        {
            object value = ReadNonnullObject("short", reader);

            if (value is short || value is byte)
            {
                return((short)value);
            }
            if (value is string)
            {
                return(PrimitiveParser.ParseShort((string)value));
            }
            PrimitiveParser.InvalidConversion("short", value);
            return(0);
        }