示例#1
0
        static void SerializePrimitive(TeraBinaryWriter writer, object value)
        {
            var type = value.GetType();

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

            if (type == typeof(bool))
            {
                writer.WriteBoolean((bool)value);
            }
            else if (type == typeof(byte))
            {
                writer.WriteByte((byte)value);
            }
            else if (type == typeof(sbyte))
            {
                writer.WriteSByte((sbyte)value);
            }
            else if (type == typeof(ushort))
            {
                writer.WriteUInt16((ushort)value);
            }
            else if (type == typeof(short))
            {
                writer.WriteInt16((short)value);
            }
            else if (type == typeof(uint))
            {
                writer.WriteUInt32((uint)value);
            }
            else if (type == typeof(int))
            {
                writer.WriteInt32((int)value);
            }
            else if (type == typeof(ulong))
            {
                writer.WriteUInt64((ulong)value);
            }
            else if (type == typeof(long))
            {
                writer.WriteInt64((long)value);
            }
            else if (type == typeof(float))
            {
                writer.WriteSingle((float)value);
            }
            else if (type == typeof(Vector3))
            {
                writer.WriteVector3((Vector3)value);
            }
            else if (type == typeof(EntityId))
            {
                writer.WriteEntityId((EntityId)value);
            }
            else if (type == typeof(SkillId))
            {
                writer.WriteSkillId((SkillId)value);
            }
            else if (type == typeof(Angle))
            {
                writer.WriteAngle((Angle)value);
            }
            else
            {
                throw Assert.Unreachable();
            }
        }