Exemple #1
0
        public JsonNetNode(string name, JObject node) {

            Name = name;
            Attributes = new List<IAttribute>();
            SubNodes = new List<INode>();

            if (node == null)
                return;

            foreach (var pair in node) {
                var key = pair.Key;
                var token = pair.Value;
                switch (token.Type) {
                    case JTokenType.Object:
                        break;
                    case JTokenType.Property:
                        break;
                    case JTokenType.None:
                        break;
                    case JTokenType.Null:
                        break;
                    case JTokenType.Array:
                        var subNode = new JsonNetNode(key, null);
                        foreach (var item in (JArray)token) {
                            subNode.SubNodes.Add(new JsonNetNode("add", (JObject)item));
                        }
                        SubNodes.Add(subNode);
                        break;
                    default:
                        Attributes.Add(new NodeAttribute() { Name = key, Value = token.ToString() });
                        break;
                }
            }

        }
Exemple #2
0
        public JsonNetNode(string name, JObject node)
        {
            Name       = name;
            Attributes = new List <IAttribute>();
            SubNodes   = new List <INode>();

            if (node == null)
            {
                return;
            }

            foreach (var pair in node)
            {
                var key   = pair.Key;
                var token = pair.Value;
                switch (token.Type)
                {
                case JTokenType.Object:
                    break;

                case JTokenType.Property:
                    break;

                case JTokenType.None:
                    break;

                case JTokenType.Null:
                    break;

                case JTokenType.Array:
                    var subNode = new JsonNetNode(key, null);
                    foreach (var item in (JArray)token)
                    {
                        subNode.SubNodes.Add(new JsonNetNode("add", (JObject)item));
                    }
                    SubNodes.Add(subNode);
                    break;

                default:      // a value
                    Attributes.Add(new NodeAttribute()
                    {
                        Name = key, Value = token
                    });
                    break;
                }
            }
        }