Ejemplo n.º 1
0
        private static void SerializeChild(string name, object value, System.Type type, bool simpleType, SerializationAttribute attr, Tag parent)
        {
            Tag tag = new Tag(name);

            if ((!simpleType || type == typeof(object)) && (value != null && !ReflectionHelper.IsNullable(type)) && value.GetType() != type)
            {
                type        = value.GetType();
                tag["type"] = (object)ReflectionHelper.GetShortAssemblyQualifiedName(type);
            }
            if (simpleType)
            {
                tag.AddValue(value);
            }
            else if (type == typeof(Color))
            {
                Color color = (Color)value;
                SdlSerializer.AddValueList(tag, (object)color.R, (object)color.G, (object)color.B);
                if ((int)color.A != (int)byte.MaxValue)
                {
                    tag.AddValue((object)color.A);
                }
            }
            else if (type == typeof(Vector2))
            {
                Vector2 vector2 = (Vector2)value;
                SdlSerializer.AddValueList(tag, (object)vector2.X, (object)vector2.Y);
            }
            else if (type == typeof(Vector3))
            {
                Vector3 vector3 = (Vector3)value;
                SdlSerializer.AddValueList(tag, (object)vector3.X, (object)vector3.Y, (object)vector3.Z);
            }
            else if (type == typeof(Vector4))
            {
                Vector4 vector4 = (Vector4)value;
                SdlSerializer.AddValueList(tag, (object)vector4.X, (object)vector4.Y, (object)vector4.Z, (object)vector4.W);
            }
            else if (type == typeof(Quaternion))
            {
                Quaternion quaternion = (Quaternion)value;
                SdlSerializer.AddValueList(tag, (object)quaternion.X, (object)quaternion.Y, (object)quaternion.Z, (object)quaternion.W);
            }
            else if (type == typeof(Matrix))
            {
                SdlSerializer.SerializeMatrix(tag, (Matrix)value);
            }
            else if (ReflectionHelper.IsGenericDictionary(type))
            {
                SdlSerializer.SerializeDictionary(tag, value as IDictionary, attr.CollectionItemName);
            }
            else if (ReflectionHelper.IsGenericCollection(type))
            {
                SdlSerializer.SerializeCollection(tag, value as IEnumerable, attr.CollectionItemName);
            }
            else
            {
                SdlSerializer.SerializeInternal(value, type, tag);
            }
            parent.AddChild(tag);
        }