public static void SaveSettings() { XMLScribe scribe = new XMLScribe(SettingsPath); scribe.mode = XMLScribe.ScribeMode.Saving; scribe.EnterNode("Settings"); { XmlNode settingData = scribe.EnterNode("SettingsData"); scribe.SaveValueIntoNode(data); scribe.ExitNode(); } scribe.ExitNode(); scribe.SaveDocument(); }
public static void ReloadSettings() { Log.Message($"Settings file: {SettingsPath}"); if (System.IO.File.Exists(SettingsPath)) { Log.Message("Settings file found."); XMLScribe scribe = new XMLScribe(SettingsPath); scribe.mode = XMLScribe.ScribeMode.Loading; scribe.EnterNode("Settings"); { scribe.LookupValue(ref data, "SettingsData"); } scribe.ExitNode(); } else { Log.Message("Settings file NOT found."); } }
public override void SaveToXML(object targetObject, XMLScribe scribe) { //Log.Message($"[Object] SaveToXML='{targetObject?.ToString()}'"); if (targetObject == null) { return; } Type type = targetObject.GetType(); //Custom behavior. if (targetObject is IExposeData exposed) { exposed.ExposeData(scribe); return; } //Default behavior. if (type.IsClass) { foreach (FieldInfo field in type.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance)) { //Log.Message($"Field='{field.Name}'"); XMLTypeConverter converter = XMLTools.GetXMLProperTypeConverter(field.FieldType); if (converter == null) { Log.Error($"Found no suitable converter for Node='{(scribe.Current.Name + '/' + field.Name)}' in Document='{scribe.DocumentPath}'"); } else { object targetObjectField = field.GetValue(targetObject); XmlNode targetNode = scribe.EnterNode(field.Name); converter.SaveToXML(targetObjectField, scribe); scribe.ExitNode(); } } } }