예제 #1
0
        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();
        }
예제 #2
0
        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.");
            }
        }
예제 #3
0
        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();
                    }
                }
            }
        }