public static void SerializeProperties(ISerializableEntity obj, XElement element, bool saveIfDefault = false)
        {
            var saveProperties = GetProperties <Serialize>(obj);

            foreach (var property in saveProperties)
            {
                object value = property.GetValue();
                if (value == null)
                {
                    continue;
                }

                if (!saveIfDefault)
                {
                    //only save
                    //  - if the attribute is saveable and it's different from the default value
                    //  - or can be changed in-game or in the editor
                    bool save = false;
                    foreach (var attribute in property.Attributes.OfType <Serialize>())
                    {
                        if ((attribute.isSaveable && !attribute.defaultValue.Equals(value)) ||
                            property.Attributes.OfType <Editable>().Any())
                        {
                            save = true;
                            break;
                        }
                    }

                    if (!save)
                    {
                        continue;
                    }
                }

                string stringValue;
                string typeName;
                if (!supportedTypes.TryGetValue(value.GetType(), out typeName))
                {
                    if (property.PropertyType.IsEnum)
                    {
                        stringValue = value.ToString();
                    }
                    else
                    {
                        DebugConsole.ThrowError("Failed to serialize the property \"" + property.Name + "\" of \"" + obj + "\" (type " + property.PropertyType + " not supported)");
                        continue;
                    }
                }
                else
                {
                    switch (typeName)
                    {
                    case "float":
                        //make sure the decimal point isn't converted to a comma or anything else
                        stringValue = ((float)value).ToString("G", CultureInfo.InvariantCulture);
                        break;

                    case "vector2":
                        stringValue = XMLExtensions.Vector2ToString((Vector2)value);
                        break;

                    case "vector3":
                        stringValue = XMLExtensions.Vector3ToString((Vector3)value);
                        break;

                    case "vector4":
                        stringValue = XMLExtensions.Vector4ToString((Vector4)value);
                        break;

                    case "color":
                        stringValue = XMLExtensions.ColorToString((Color)value);
                        break;

                    case "rectangle":
                        stringValue = XMLExtensions.RectToString((Rectangle)value);
                        break;

                    default:
                        stringValue = value.ToString();
                        break;
                    }
                }

                element.SetAttributeValue(property.Name.ToLowerInvariant(), stringValue);
            }
        }