public static Type GetRuntimeType(this VariableSave variableSave) { string typeAsString = variableSave.Type; Type foundType = GetPrimitiveType(typeAsString); if (foundType != null) { return(foundType); } if (variableSave.GetIsEnumeration()) { return(TypeManager.Self.GetTypeFromString(variableSave.Type)); } else { return(typeof(object)); } }
/// <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 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 }