/// <summary>
        /// Converts integer values to their corresponding enumeration values. This should be called
        /// after variable saves are loaded from XML.
        /// </summary>
        /// <param name="variableSave">The VariableSave to fix.</param>
        /// <returns>Whether any changes were made.</returns>
        public static bool FixEnumerations(this VariableSave variableSave)
        {
#if GUM
            if (variableSave.GetIsEnumeration() && variableSave.Value != null && variableSave.Value.GetType() == typeof(int))
            {
                Array array = Enum.GetValues(variableSave.GetRuntimeType());

                // GetValue returns the value at an index, which is bad if there are
                // gaps in the index
                // variableSave.Value = array.GetValue((int)variableSave.Value);
                for (int i = 0; i < array.Length; i++)
                {
                    if ((int)array.GetValue(i) == (int)variableSave.Value)
                    {
                        variableSave.Value = array.GetValue(i);
                        return(true);
                    }
                }

                return(false);
            }
            return(false);
#else
            if (variableSave.Value != null && variableSave.Value is int)
            {
                switch (variableSave.Type)
                {
                case "DimensionUnitType":
                case "Gum.DataTypes.DimensionUnitType":
                    variableSave.Value = (Gum.DataTypes.DimensionUnitType)variableSave.Value;

                    return(true);

                case "VerticalAlignment":
                case "RenderingLibrary.Graphics.VerticalAlignment":

                    variableSave.Value = (global::RenderingLibrary.Graphics.VerticalAlignment)variableSave.Value;
                    return(true);

                case "HorizontalAlignment":
                case "RenderingLibrary.Graphics.HorizontalAlignment":
                    variableSave.Value = (global::RenderingLibrary.Graphics.HorizontalAlignment)variableSave.Value;
                    return(true);

                case "PositionUnitType":
                case "Gum.Managers.PositionUnitType":
                    variableSave.Value = (Gum.Managers.PositionUnitType)variableSave.Value;
                    return(true);

                case "GeneralUnitType":
                case "Gum.Converters.GeneralUnitType":
                    variableSave.Value = (Gum.Converters.GeneralUnitType)variableSave.Value;
                    return(true);

                case "Gum.RenderingLibrary.Blend":
                case "Blend":
                    variableSave.Value = (Gum.RenderingLibrary.Blend)variableSave.Value;
                    return(true);

                case "Gum.Managers.TextureAddress":
                case "TextureAddress":

                    variableSave.Value = (TextureAddress)variableSave.Value;
                    return(true);

                case "Gum.Managers.ChildrenLayout":
                case "ChildrenLayout":
                    variableSave.Value = (ChildrenLayout)variableSave.Value;
                    return(true);

                default:
                    return(false);
                }
            }

            return(false);
#endif
        }
        public static TypeConverter GetTypeConverter(this VariableSave variableSave, ElementSave container = null)
        {
            ElementSave       categoryContainer;
            StateSaveCategory category;

            if (variableSave.CustomTypeConverter != null)
            {
                return(variableSave.CustomTypeConverter);
            }
            else if (variableSave.IsFont)
            {
                return(new FontTypeConverter());
            }
            else if (variableSave.Name == "Guide")
            {
                AvailableGuidesTypeConverter availableGuidesTypeConverter = new AvailableGuidesTypeConverter();
                availableGuidesTypeConverter.GumProjectSave = ObjectFinder.Self.GumProjectSave;
                availableGuidesTypeConverter.ShowNewGuide   = false;
                return(availableGuidesTypeConverter);
            }
            else if (variableSave.IsState(container, out categoryContainer, out category))
            {
                string categoryName = null;

                if (category != null)
                {
                    categoryName = category.Name;
                }

                AvailableStatesConverter converter = new AvailableStatesConverter(categoryName);
                converter.ElementSave = categoryContainer;
                return(converter);
            }
            else
            {
                // We should see if it's an exposed variable, and if so, let's look to the source object's type converters
                bool foundInRoot = false;
                if (!string.IsNullOrEmpty(variableSave.SourceObject) && container != null)
                {
                    InstanceSave instance = container.GetInstance(variableSave.SourceObject);

                    if (instance != null)
                    {
                        // see if the instance has a variable
                        var foundElementSave = ObjectFinder.Self.GetRootStandardElementSave(instance);

                        if (foundElementSave != null)
                        {
                            VariableSave rootVariableSave = foundElementSave.DefaultState.GetVariableSave(variableSave.GetRootName());

                            if (rootVariableSave != null)
                            {
                                return(rootVariableSave.GetTypeConverter((ElementSave)null));
                            }
                        }
                    }
                }
            }
            Type type = variableSave.GetRuntimeType();

            return(variableSave.GetTypeConverter(type));
        }
        public static void FixEnumerations(this VariableSave variableSave)
        {
#if GUM
            if (variableSave.GetIsEnumeration() && variableSave.Value != null && variableSave.Value.GetType() == typeof(int))
            {
                Array array = Enum.GetValues(variableSave.GetRuntimeType());

                variableSave.Value = array.GetValue((int)variableSave.Value);
            }
#else
            if (variableSave.Value != null && variableSave.Value is int)
            {
                switch (variableSave.Type)
                {
                case "DimensionUnitType":
                case "Gum.DataTypes.DimensionUnitType":
                    variableSave.Value = (Gum.DataTypes.DimensionUnitType)variableSave.Value;
                    break;

                case "VerticalAlignment":
                case "RenderingLibrary.Graphics.VerticalAlignment":

                    variableSave.Value = (global::RenderingLibrary.Graphics.VerticalAlignment)variableSave.Value;
                    break;

                case "HorizontalAlignment":
                case "RenderingLibrary.Graphics.HorizontalAlignment":
                    variableSave.Value = (global::RenderingLibrary.Graphics.HorizontalAlignment)variableSave.Value;
                    break;

                case "PositionUnitType":
                case "Gum.Managers.PositionUnitType":
                    variableSave.Value = (Gum.Managers.PositionUnitType)variableSave.Value;
                    break;

                case "GeneralUnitType":
                case "Gum.Converters.GeneralUnitType":
                    variableSave.Value = (Gum.Converters.GeneralUnitType)variableSave.Value;
                    break;

                case "Gum.RenderingLibrary.Blend":
                case "Blend":
                    variableSave.Value = (Gum.RenderingLibrary.Blend)variableSave.Value;
                    break;

                case "Gum.Managers.TextureAddress":
                case "TextureAddress":

                    variableSave.Value = (TextureAddress)variableSave.Value;
                    break;

                case "Gum.Managers.ChildrenLayout":
                case "ChildrenLayout":
                    variableSave.Value = (ChildrenLayout)variableSave.Value;
                    break;

                default:
                    break;
                }
            }
#endif
        }