Utility class for extracting typed values from strings.
Example #1
0
        public static char ReadChar(NetworkBinaryReader reader)
        {
            object value = ReadNonnullObject("char", reader);

            if (value is char)
            {
                return((char)value);
            }
            throw PrimitiveParser.CreateProtocolViolationException("char", value);
        }
        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);
        }
Example #3
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));
            }
            throw PrimitiveParser.CreateProtocolViolationException("float", value);
        }
Example #4
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));
            }
            throw PrimitiveParser.CreateProtocolViolationException("long", value);
        }
Example #5
0
        public static int ReadInt32(NetworkBinaryReader reader)
        {
            object value = ReadNonnullObject("int", reader);

            if (value is int || value is short || value is byte)
            {
                return((int)value);
            }
            if (value is string)
            {
                return(PrimitiveParser.ParseInt((string)value));
            }
            throw PrimitiveParser.CreateProtocolViolationException("int", value);
        }
Example #6
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));
            }
            throw PrimitiveParser.CreateProtocolViolationException("double", value);
        }
Example #7
0
        public static byte[] ReadBytes(NetworkBinaryReader reader)
        {
            object value = ReadObject(reader);

            if (value == null)
            {
                return(null);
            }
            if (value is byte[])
            {
                return((byte[])value);
            }
            throw PrimitiveParser.CreateProtocolViolationException("byte[]", value);
        }
Example #8
0
        public static string ReadString(NetworkBinaryReader reader)
        {
            object value = ReadObject(reader);

            if (value == null)
            {
                return(null);
            }
            if (value is byte[])
            {
                throw PrimitiveParser.CreateProtocolViolationException("string", value);
            }
            return(value.ToString());
        }
Example #9
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));
            }
            throw PrimitiveParser.CreateProtocolViolationException("byte", value);
        }
Example #10
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);
        }
Example #11
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());
        }
Example #12
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);
        }
Example #13
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);
        }
Example #14
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);
        }
Example #15
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);
        }
Example #16
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);
        }
Example #17
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);
        }