string JsonValueString(LightJson.JsonValue val) { switch (val.Type) { case LightJson.JsonValueType.Null: return("[null]"); case LightJson.JsonValueType.Boolean: return(val.AsBoolean.ToString()); case LightJson.JsonValueType.Number: if (val.IsInteger) { return(val.AsInteger.ToString()); } return(val.AsNumber.ToString()); case LightJson.JsonValueType.String: return(string.Format("\"{0}\"", val.AsString)); case LightJson.JsonValueType.Object: break; case LightJson.JsonValueType.Array: break; default: break; } return("[null]"); }
void AssignSubNode(LightJson.JsonArray val, TreeNode vNode) { while (vNode.Nodes.Count > val.Count) { vNode.Nodes.RemoveAt(vNode.Nodes.Count - 1); } for (int i = 0; i < val.Count; i++) { LightJson.JsonValue subval = val[i]; string strKey = string.Format("[{0}]", i); string strTxt = strKey; if (IsSimple(subval)) { strTxt += string.Format(" : {0}", JsonValueString(subval)); } TreeNode subNode = null; if (vNode.Nodes.ContainsKey(strKey)) { subNode = vNode.Nodes[strKey]; } else { subNode = vNode.Nodes.Add(strKey, strTxt); } subNode.Text = strTxt; subNode.Tag = subval; SetNodeIcon(subNode, subval); AssignSubNode(subval, subNode); } }
void SetNodeIcon(TreeNode vNode, LightJson.JsonValue val) { string strImg = JsonIcon(val); vNode.ImageKey = strImg; vNode.ContextMenuStrip = contextMenuStrip1; vNode.SelectedImageKey = strImg; }
void OpenJson(LightJson.JsonValue val) { m_val = val; m_bInner = true; richTextBoxView.Text = val.ToString(); m_bInner = false; AssignTree(val); }
private void ToolStripMenuItemCopyAll_Click(object sender, EventArgs e) { LightJson.JsonValue val = SelectValue(); TreeNode vNode = treeViewObject.SelectedNode; LightJson.JsonObject o = new LightJson.JsonObject(); o[vNode.Name] = val; val = o; Clipboard.SetText(val.ToString(true)); }
void AssignSubNode(LightJson.JsonValue val, TreeNode vNode) { if (val.IsJsonObject) { vNode.Nodes.Add(ReplaceNode()); } else if (val.IsJsonArray) { vNode.Nodes.Add(ReplaceNode()); } }
bool IsSimple(LightJson.JsonValue val) { if (val.IsJsonObject) { return(false); } if (val.IsJsonArray) { return(false); } return(true); }
string JsonIcon(LightJson.JsonValue val) { if (val.IsJsonObject) { return("Object"); } if (val.IsJsonArray) { return("Array"); } return("Property"); }
/* * the actual entry point : ---. \|/ * ' for opcodes */ public static FullType FromJson <FullType> (JsonValue JV) { Mapping.ConsumerBase Consumer = Mapping.GetConsumer(typeof(FullType)); Type normalizedType = Consumer.expected_RHS_Type; SObject intermediateVal = PLJGlue.Convert(normalizedType, JV); MethodInfo closedRoundabout = typeof(LightJSonAdapter).GetMethod("roundabout").MakeGenericMethod(new [] { normalizedType, typeof(FullType) }); try { return((FullType)closedRoundabout.Invoke(null, new object [] { intermediateVal, Consumer.F })); } catch (TargetInvocationException e) { throw e.InnerException; // the actual exception whithin the function being invoked ( gets wrapped by reflection ) } }
private void ToolStripMenuItemCopyValue_Click(object sender, EventArgs e) { LightJson.JsonValue val = SelectValue(); if (IsSimple(val)) { Clipboard.SetText(val.ToString()); } else { TreeNode vNode = treeViewObject.SelectedNode; Clipboard.SetText(vNode.Name); } }
private void TreeViewObject_BeforeExpand(object sender, TreeViewCancelEventArgs e) { if (!e.Node.Nodes.ContainsKey(m_RepalceKey)) { return; } e.Node.Nodes.Clear(); LightJson.JsonValue val = (LightJson.JsonValue)e.Node.Tag; if (val.IsJsonObject) { AssignSubNode(val.AsJsonObject, e.Node); } else if (val.IsJsonArray) { AssignSubNode(val.AsJsonArray, e.Node); } }
void OpenFile(string strFileName) { try { LightJson.JsonValue val = LightJson.Serialization.JsonReader.ParseFile(strFileName); if (!val.IsNull) { m_strFileName = strFileName; RefreshTitle(); OpenJson(val); WatchFile(m_strFileName); } } catch (Exception ee) { MessageBox.Show(ee.Message); } }
public static void Test1() { var X = new Mapping.ConsumerIndexer_New_LHS <Vector3, float>(3); string dummy = ""; JsonValue JV_dim1_arr3 = PLJGlue.ParseWithRest("[1,2,3]", out dummy); Console.WriteLine(FromJson <Vector3> (JV_dim1_arr3)); Console.WriteLine(FromJson <float[]> (JV_dim1_arr3)); JsonValue JV_dim2_arr44 = PLJGlue.ParseWithRest("[[1,2,3,4],[1,2,3,4],[1,2,3,4],[1,2,3,4]]", out dummy); JsonValue JV_dim2_arr28 = PLJGlue.ParseWithRest("[[1,2,3,4,1,2,3,4],[1,2,3,4,1,2,3,4]]", out dummy); Console.WriteLine(FromJson <Matrix4x4> (JV_dim2_arr44)); Console.WriteLine(FromJson <UnityEngine.Rendering.SphericalHarmonicsL2> (JV_dim2_arr28)); }
private void RichTextBoxView_TextChanged(object sender, EventArgs e) { if (m_bInner) { return; } try { LightJson.JsonValue val = LightJson.Serialization.JsonReader.Parse(richTextBoxView.Text); if (!val.IsNull) { OpenJson(val); } } catch (Exception ee) { MessageBox.Show(ee.Message); } }
void AssignTree(LightJson.JsonValue val) { TreeNode vRoot = null; treeViewObject.Nodes.Clear(); if (treeViewObject.Nodes.ContainsKey("JSON")) { vRoot = treeViewObject.Nodes["JSON"]; } else { vRoot = treeViewObject.Nodes.Add("JSON", "JSON"); } vRoot.Tag = val; SetNodeIcon(vRoot, val); vRoot.Nodes.Add(ReplaceNode()); if (!vRoot.IsExpanded) { vRoot.Expand(); } }
public static SObject FromJson(JsonValue JV, Type fullType) { try { return(FromJsonMI.MakeGenericMethod(new [] { fullType }).Invoke(null, new object[] { JV })); } catch (TargetInvocationException e) { throw e.InnerException; } }