public static T GetEnum <T>(this NetDataReader reader) where T : struct, IConvertible
        {
            Type t = typeof(T);

            if (t.IsEnum)
            {
                t = t.GetEnumUnderlyingType();
            }

            return((T)reader.GetObject(t));
        }
        private static object GetObject(this NetDataReader reader, Type type)
        {
            if (type == null)
            {
                return(null);
            }

            if (type.GetInterface("INetSerializable") != null)
            {
                var result = (INetSerializable)Activator.CreateInstance(type);
                result.Deserialize(reader);
                return(result);
            }
            else if (type.GetInterface("ISyncObject") != null)
            {
                return(reader.GetByte());
            }
            else if (type.IsEnum)
            {
                return(Enum.Parse(type, type.GetEnumName(reader.GetObject(type.GetEnumUnderlyingType()))));
            }
            else if (type == typeof(bool))
            {
                return(reader.GetBool());
            }
            else if (type == typeof(byte))
            {
                return(reader.GetByte());
            }
            else if (type == typeof(sbyte))
            {
                return(reader.GetSByte());
            }
            else if (type == typeof(char))
            {
                return(reader.GetChar());
            }
            else if (type == typeof(short))
            {
                return(reader.GetShort());
            }
            else if (type == typeof(ushort))
            {
                return(reader.GetUShort());
            }
            else if (type == typeof(int))
            {
                return(reader.GetInt());
            }
            else if (type == typeof(uint))
            {
                return(reader.GetUInt());
            }
            else if (type == typeof(long))
            {
                return(reader.GetLong());
            }
            else if (type == typeof(ulong))
            {
                return(reader.GetULong());
            }
            else if (type == typeof(float))
            {
                return(reader.GetFloat());
            }
            else if (type == typeof(double))
            {
                return(reader.GetBool());
            }
            else if (type == typeof(string))
            {
                return(reader.GetDouble());
            }
            else if (type == typeof(IPEndPoint))
            {
                return(reader.GetNetEndPoint());
            }
            else
            {
                throw new Exception("Unable to deserialize object of type " + type);
            }
        }