public void SaveSettings() { Dictionary <System.Enum, System.Enum>[] buffer = new Dictionary <System.Enum, System.Enum> [2]; buffer[0] = PrimaryControlSettings; buffer[1] = SecondaryControlSettings; Seralizer <ICollection <Dictionary <System.Enum, System.Enum> >, Dictionary <System.Enum, System.Enum> > .Serialize(buffer, "ControllSettings.dat"); }
/// <summary> /// Converts the Data XML to the native type. This was necessary because WCF wanted the exact type, but it's only know at the source and destination. /// </summary> /// <typeparam name="T">Type to convert to</typeparam> /// <returns>Concrete type</returns> /// <exception cref="SerializationFailedException"></exception> public virtual T DataToType <T>() { if (Seralization == SeralizeAs.Xml) { try { return(Seralizer.StringToObject <T>(Data)); } catch (System.InvalidOperationException ex) { throw new SerializationFailedException($"Verify the type '{typeof(T)}' is the same type being passed in as the argument, otherwise check the inner exception", ex); } } else if (Seralization == SeralizeAs.Json) { try { return(Newtonsoft.Json.JsonConvert.DeserializeObject <T>(Data)); } catch (Newtonsoft.Json.JsonReaderException ex) { throw new SerializationFailedException($"Verify the type '{typeof(T)}' is the same type being passed in as the argument, otherwise check the inner exception", ex); } } else { throw new InvalidOperationException("Unknown encoding type selected"); } }
public void LoadSettings() { Dictionary <System.Enum, System.Enum>[] buffer = new Dictionary <System.Enum, System.Enum> [2]; buffer = (Dictionary <System.Enum, System.Enum>[]) Seralizer <ICollection <Dictionary <System.Enum, System.Enum> >, Dictionary <System.Enum, System.Enum> > .Deseialize("ControllSettings.dat"); PrimaryControlSettings = buffer[0]; SecondaryControlSettings = buffer[1]; }
private void GenerateButton_Click(object sender, RoutedEventArgs e) { SelectedCharacter = new Character(false); DisplayCharacterStats(); Characters.Add(SelectedCharacter); AddCharacterItemBoxToCharacterListBox(SelectedCharacter); if (EditButton.Visibility != Visibility.Visible) { EditButton.Visibility = Visibility.Visible; } Seralizer.SerializeCharacters(Characters); }
public ViewCharacters() { InitializeComponent(); this.DataContext = SelectedCharacter; Characters = Seralizer.DeserializeCharacters(); LoadCharacterListBox(); if (Characters.Count > 0) { EditButton.Visibility = Visibility.Visible; SelectedCharacter = Characters[0]; DisplayCharacterStats(); } }
/// <summary> /// Centralized location for seralization, but does not set any members on the class. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="data"></param> /// <param name="seralization"></param> /// <returns></returns> public static string Encode <T>(T data, SeralizeAs seralization) { if (seralization == SeralizeAs.Xml) { return(Seralizer.ObjectToXmlString <T>(data)); } else if (seralization == SeralizeAs.Json) { return(Newtonsoft.Json.JsonConvert.SerializeObject(data)); } else { throw new InvalidOperationException("Unknown seralization selected"); } }