Exemple #1
0
        /// <summary>
        /// Compares a type of object to the Networking Stream
        /// </summary>
        /// <typeparam name="T">Value type to get out of it</typeparam>
        /// <param name="stream">Stream to be used</param>
        /// <param name="o">Object being compared with</param>
        /// <returns>Returns the type of comparison passed</returns>
        public static bool Compare <T>(NetworkingStream stream, object o)
        {
            stream.StartPeek();
            object obj = null;

            if (typeof(T) == typeof(string))
            {
                obj = MapString(stream);
            }
            else if (typeof(T) == typeof(Vector3))
            {
                obj = MapVector3(stream);
            }
            else if (typeof(T) == typeof(Vector4) || typeof(T) == typeof(Color) || typeof(T) == typeof(Quaternion))
            {
                obj = MapVector4(typeof(T), stream);
            }
            else if (typeof(T) == typeof(byte[]))
            {
                obj = MapByteArray(stream);
            }
            else if (typeof(T) == typeof(BMSByte))
            {
                obj = MapBMSByte(stream);
            }
            else
            {
                obj = MapBasicType(typeof(T), stream);
            }

            stream.StopPeek();

            return(Equals(o, obj));
        }
        /// <summary>
        /// Compares a type of object to the Networking Stream
        /// </summary>
        /// <typeparam name="T">Value type to get out of it</typeparam>
        /// <param name="stream">Stream to be used</param>
        /// <param name="o">Object being compared with</param>
        /// <returns>Returns the type of comparison passed</returns>
        public static bool Compare <T>(NetworkingStream stream, object o)
        {
            stream.StartPeek();
            object obj         = null;
            var    genericType = typeof(T);

            if (genericType == typeof(string))
            {
                obj = MapString(stream);
            }
            else if (genericType == typeof(Vector3))
            {
                obj = MapVector3(stream);
            }
            else if (genericType == typeof(Vector4) || genericType == typeof(Color) || genericType == typeof(Quaternion))
            {
                obj = MapVector4(genericType, stream);
            }
            else if (genericType == typeof(byte[]))
            {
                obj = MapByteArray(stream);
            }
            else if (genericType == typeof(BMSByte))
            {
                obj = MapBMSByte(stream);
            }
            else if (genericType.IsEnum())
            {
                obj = MapBasicType(Enum.GetUnderlyingType(genericType), stream);
            }
            else
            {
                obj = MapBasicType(genericType, stream);
            }

            stream.StopPeek();

            return(Equals(o, obj));
        }