Пример #1
0
        private GUIObject LoadTree(string fileName)
        {
            string data = File.ReadAllText(fileName, Encoding.UTF8);
            JsonSerializerSettings settings = new JsonSerializerSettings();

            settings.TypeNameHandling = TypeNameHandling.Objects;
            settings.Binder           = new TypeBinder();
            settings.Converters.Add(new StringEnumConverter());
            GUIObject obj = JsonConvert.DeserializeObject <GUIObject>(data, settings);

            obj.FixAfterLoad();
            return(obj.GetRoot());
        }
Пример #2
0
        private void SaveTree(GUIObject obj, bool saveAs)
        {
            if (obj == null)
            {
                return;
            }
            if (saveAs && !GetTreeFileName(true))
            {
                return;
            }

            GUIObject root = obj.GetRoot();

            JsonSerializerSettings settings = new JsonSerializerSettings();

            settings.TypeNameHandling = TypeNameHandling.Objects;
            settings.Binder           = new TypeBinder();
            settings.Converters.Add(new StringEnumConverter());
            string data = JsonConvert.SerializeObject(root, Formatting.Indented, settings);

            File.WriteAllText(TreeFileName, data, Encoding.UTF8);
        }