private int GetIconFor(MsgPackItem item) { if (ReferenceEquals(item, null)) { return(0); } Type typ = item.GetType(); if (typ == typeof(MpBool)) { return(1); } if (typ == typeof(MpInt)) { return(2); } if (typ == typeof(MpFloat)) { return(3); } if (typ == typeof(MpBin)) { return(4); } if (typ == typeof(MpString)) { return(5); } if (typ == typeof(MpArray)) { return(6); } if (typ == typeof(MpMap)) { return(7); } if (typ == typeof(MpExt)) { return(10); } if (typ == typeof(MpError)) { return(11); } if (typ == typeof(MpRoot)) { return(12); } return(-1); }
private void Traverse(TreeNode node, MsgPackItem item) { if (ReferenceEquals(item, null)) { return; } Type typ = item.GetType(); if (typ == typeof(MpBool)) { return; } if (typ == typeof(MpInt)) { return; } if (typ == typeof(MpFloat)) { return; } if (typ == typeof(MpBin)) { return; } if (typ == typeof(MpString)) { return; } if (typ == typeof(MpArray)) { MpArray arr = (MpArray)item; MsgPackItem[] children = arr.PackedValues; for (int t = 0; t < children.Length; t++) { TreeNode child = GetTreeNodeFor(children[t]); node.Nodes.Add(child); Traverse(child, children[t]); } } if (typ == typeof(MpMap)) { MpMap map = (MpMap)item; KeyValuePair <MsgPackItem, MsgPackItem>[] children = map.PackedValues; for (int t = 0; t < children.Length; t++) { TreeNode child = GetTreeNodeFor(children[t].Key); child.StateImageIndex = 8; // Key node.Nodes.Add(child); Traverse(child, children[t].Key); TreeNode childVal = GetTreeNodeFor(children[t].Value); childVal.StateImageIndex = 9; // Value child.Nodes.Add(childVal); Traverse(childVal, children[t].Value); } } if (typ == typeof(MpError)) { MpError err = (MpError)item; if (!ReferenceEquals(err.PartialItem, null)) { if (!(err.PartialItem is MpError)) { node.StateImageIndex = GetIconFor(err.PartialItem); } TreeNode child = GetTreeNodeFor(err.PartialItem); node.Nodes.Add(child); Traverse(child, err.PartialItem); } } }