public JsonArray(JToken obj) { elems = new List <AElement>(); foreach (var it in (JArray)obj) { elems.Add(AElement.Create(it)); } }
public Instruction(JObject obj) { fn = (string)obj["fn"]; op = (string)obj["op"]; arg0 = AElement.Create(obj["arg0"]); arg1 = AElement.Create(obj["arg1"]); arg2 = AElement.Create(obj["arg2"]); arg3 = AElement.Create(obj["arg3"]); }
private void grid_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e) { AElement obj = grid.SelectedItem as AElement; if (obj == null) { return; } tree.Items.Clear(); obj.AddChildsToTree(tree.Items); foreach (var it in tree.Items) { ExpandAll(it as TreeViewItem); } }
public JsonObject(JToken obj) { elems = new Dictionary <AElement, AElement>(); ObjectType = "Unknown type"; foreach (var it in (JObject)obj) { if (it.Key == "ObjectType") { ObjectType = (string)it.Value; } else { elems[AElement.Create(it.Key)] = AElement.Create(it.Value); } } }
private bool ParseJson(string fn) { JToken rootToken = JToken.ReadFrom(new JsonTextReader(File.OpenText(fn))); if (rootToken == null) { Console.WriteLine("root is null"); return(false); } if (rootToken.Type != JTokenType.Array) { MessageBox.Show(this, " isn't an array (is " + rootToken.Type + ")."); return(false); } JArray root = (JArray)rootToken; instructionsList = new List <Instruction>(); Dictionary <UInt32, AElement> objects = new Dictionary <uint, AElement>(); foreach (JObject it in root) { if ((string)it["type"] == "instruction") { Instruction instruction = new Instruction(it); instruction.Load(objects); instructionsList.Add(instruction); } else if ((string)it["type"] == "object") { UInt32 addr = AObject.StrToAddr((string)it["address"]); JToken content = it["content"]; if (content != null) { objects[addr] = AElement.Create(content); } else { //Console.WriteLine("Invalid object " + addr + ": content is null."); objects[addr] = new Null(); } } } grid.ItemsSource = instructionsList; return(true); }
public override void Load(Dictionary <UInt32, AElement> objects) { if (target != null) { return; } if (objects.TryGetValue(addr, out target)) { target.Load(objects); } else { Console.WriteLine("Unknown object at address " + addr); target = null; } }
public override void AddChildsToTree(ItemCollection items) { JsonArray nodes = this["_nodes"] as JsonArray; foreach (AElement it in nodes) { AElement key = (it as JsonObject)["key"]; AElement val = (it as JsonObject)["val"]; if (key.Type == JTokenType.String || key.Type == JTokenType.Null) { items.Add(val.ToTreeItem(key.GetTreeLabel())); } else { items.Add(key.ToTreeItem("key")); items.Add(val.ToTreeItem("val")); } } }
public Reference(JToken obj) { addr = AObject.StrToAddr((string)obj); target = null; isRecursing = false; }