コード例 #1
0
ファイル: Item.cs プロジェクト: TheNicker/NetSettings
        public static ItemTree FromFile(string aFileName)
        {
            string   text = File.ReadAllText(aFileName);
            ItemTree root = (ItemTree)Newtonsoft.Json.JsonConvert.DeserializeObject(text, typeof(ItemTree));

            return(root);
        }
コード例 #2
0
        static public void SaveToFile(ItemTree root, Dictionary <string, object> dataBindings, string filePath)
        {
            //Build json object from dataBindings
            var rootJsonObject          = new JObject();
            NameToJsonObject mapObjects = new NameToJsonObject();

            root.FullName = "";
            BuildTree(root, rootJsonObject, mapObjects);

            //update json object with data in databindings.
            foreach (var pair in dataBindings)
            {
                if (dataBindings[pair.Key] == null)
                {
                    mapObjects[pair.Key].Value = null;
                }
                else
                {
                    mapObjects[pair.Key].Value = JToken.FromObject(dataBindings[pair.Key]);
                }
            }

            //Serialize json
            string text = JsonConvert.SerializeObject(rootJsonObject, new Newtonsoft.Json.JsonSerializerSettings()
            {
                Formatting = Formatting.Indented
            });

            //write serialized json to disk
            File.WriteAllText(filePath, text);
        }
コード例 #3
0
        static private void BuildTree(ItemTree root, Newtonsoft.Json.Linq.JObject rootObject, NameToJsonObject mapObjects)
        {
            if (root.type == "root" || root.type == "menu")
            {
                if (root.type == "menu")
                {
                    JObject childObject = new JObject();
                    rootObject.Add(root.name, childObject);
                    rootObject = childObject;
                }


                foreach (ItemTree subitem in root.subitems)
                {
                    BuildTree(subitem, rootObject, mapObjects);
                }
            }
            else
            {
                JProperty prop = new JProperty(root.name, null);
                rootObject.Add(prop);
                mapObjects.Add(root.FullName, prop);
            }
        }
コード例 #4
0
 public DataProvider(ItemTree aRoot)
 {
     fRootTemplate = aRoot;
     fBoundViews   = new List <DataView>();
     Initialize();
 }