protected virtual ITextNode Parse([NotNull] string name, [NotNull, ItemNotNull] JObject jobject)
        {
            var childNodes = new List <ITextNode>();
            var attributes = new List <ITextNode>();

            foreach (var property in jobject.Properties())
            {
                switch (property.Value.Type)
                {
                case JTokenType.Object:
                    var objectTextNode = Parse(property.Name, property.Value.Value <JObject>());
                    childNodes.Add(objectTextNode);
                    break;

                case JTokenType.Array:
                    var array = property.Value.Value <JArray>();
                    foreach (var element in array.OfType <JObject>())
                    {
                        var arrayTextNode = Parse(property.Name, element);
                        childNodes.Add(arrayTextNode);
                    }

                    break;

                case JTokenType.Boolean:
                case JTokenType.Date:
                case JTokenType.Float:
                case JTokenType.Integer:
                case JTokenType.String:
                    var propertyTreeNode = new JsonTextNode(this, property.Name, property);
                    attributes.Add(propertyTreeNode);
                    break;
                }
            }

            return(new JsonTextNode(this, name, jobject, attributes, childNodes));
        }
 public JsonInnerTextNode([NotNull] JsonTextNode textNode, [NotNull, ItemNotNull]  JToken token)
 {
     TextNode = textNode;
     _token   = token;
 }
        protected ITextNode Parse()
        {
            var jobject = RootToken as JObject;
            if (jobject != null)
            {
                var property = jobject.Properties().FirstOrDefault(p => p.Name != "$schema");
                if (property == null)
                {
                    return TextNode.Empty;
                }

                var value = property.Value as JObject;
                if (value == null)
                {
                    return TextNode.Empty;
                }

                _root = Parse(property.Name, value, null);
            }

            var jarray = RootToken as JArray;
            if (jarray != null)
            {
                var jsonTextNode = new JsonTextNode(this, string.Empty, jarray);
                _root = jsonTextNode;

                foreach (var jobj in jarray.OfType<JObject>())
                {
                    Parse(string.Empty, jobj, jsonTextNode);
                }
            }

            return _root;
        }
        protected virtual ITextNode Parse([NotNull] string name, [NotNull, ItemNotNull]  JObject jobject, [CanBeNull] JsonTextNode parent)
        {
            var textNodes = parent?.ChildNodes as ICollection<ITextNode>;

            var treeNode = new JsonTextNode(this, name, jobject);
            textNodes?.Add(treeNode);

            var childNodes = (ICollection<ITextNode>)treeNode.ChildNodes;
            var attributes = (ICollection<ITextNode>)treeNode.Attributes;

            foreach (var property in jobject.Properties())
            {
                switch (property.Value.Type)
                {
                    case JTokenType.Object:
                        Parse(property.Name, property.Value.Value<JObject>(), treeNode);
                        break;

                    case JTokenType.Array:
                        var array = property.Value.Value<JArray>();
                        var arrayTreeNode = new JsonTextNode(this, property.Name, array);

                        foreach (var element in array.OfType<JObject>())
                        {
                            Parse(string.Empty, element, arrayTreeNode);
                        }

                        childNodes.Add(arrayTreeNode);
                        break;

                    case JTokenType.Boolean:
                    case JTokenType.Date:
                    case JTokenType.Float:
                    case JTokenType.Integer:
                    case JTokenType.String:
                        var propertyTreeNode = new JsonTextNode(this, property.Name, property);
                        attributes.Add(propertyTreeNode);
                        break;
                }
            }

            return treeNode;
        }